1
0
Fork 0
mirror of https://github.com/ansible-collections/hetzner.hcloud.git synced 2026-02-04 08:01:49 +00:00

fix!: do not detach volume if server is not provided (#632)

Do not detach volume if `server` is not provided

##### SUMMARY

Volumes were automatically detached from servers if they already exists
and attached to a server.
This PR fixes this issue after adding new ```volume_attachment``` module
so user can attach/detach
volumes with that module

Fixes: #490 

##### ISSUE TYPE
- Bugfix Pull Request

##### COMPONENT NAME
```volume```

---------

Co-authored-by: Jonas L. <jooola@users.noreply.github.com>
This commit is contained in:
Amirhossein Shaerpour 2025-05-07 12:14:39 +03:30 committed by GitHub
parent 3c84f19ef5
commit e8fda3557c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 2 additions and 28 deletions

View file

@ -0,0 +1,2 @@
breaking_changes:
- volume - Volumes are no longer detached when the server argument is not provided. Please use the ``volume_attachment`` module to manage volume attachments.

View file

@ -244,12 +244,6 @@ class AnsibleHCloudVolume(AnsibleHCloud):
action = self.hcloud_volume.attach(server, automount=automount) action = self.hcloud_volume.attach(server, automount=automount)
action.wait_until_finished() action.wait_until_finished()
self._mark_as_changed() self._mark_as_changed()
else:
if self.hcloud_volume.server is not None:
if not self.module.check_mode:
action = self.hcloud_volume.detach()
action.wait_until_finished()
self._mark_as_changed()
labels = self.module.params.get("labels") labels = self.module.params.get("labels")
if labels is not None and labels != self.hcloud_volume.labels: if labels is not None and labels != self.hcloud_volume.labels:

View file

@ -99,28 +99,6 @@
- volume is not changed - volume is not changed
- volume.hcloud_volume.server == hcloud_server_name - volume.hcloud_volume.server == hcloud_server_name
- name: test detach Volume with checkmode
hetzner.hcloud.volume:
name: "{{hcloud_volume_name}}"
check_mode: true
register: volume
- name: verify detach Volume with checkmode
assert:
that:
- volume is changed
- volume.hcloud_volume.server == hcloud_server_name
- name: test detach Volume
hetzner.hcloud.volume:
name: "{{hcloud_volume_name}}"
register: volume
- name: verify detach volume
assert:
that:
- volume is changed
- volume.hcloud_volume.location == hcloud_location_name
- volume.hcloud_volume.server != hcloud_server_name
- name: test update Volume label - name: test update Volume label
hetzner.hcloud.volume: hetzner.hcloud.volume:
name: "{{hcloud_volume_name}}" name: "{{hcloud_volume_name}}"