hcloud_volume: Force detaching volume on deletion (#95)

Force detaching of volumes before deleting when they are still attached to a server. This makes it easier for tools like molecule to see the correct state.
This commit is contained in:
Lukas Kämmerling 2021-07-16 10:55:08 +02:00 committed by GitHub
parent 5d6b5b7c3f
commit f4b336a444
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 0 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- hcloud_volume Force detaching of volumes on servers before deletion

View file

@ -294,6 +294,8 @@ class AnsibleHcloudVolume(Hcloud):
self._get_volume() self._get_volume()
if self.hcloud_volume is not None: if self.hcloud_volume is not None:
if not self.module.check_mode: if not self.module.check_mode:
if self.hcloud_volume.server is not None:
self.hcloud_volume.detach().wait_until_finished()
self.client.volumes.delete(self.hcloud_volume) self.client.volumes.delete(self.hcloud_volume)
self._mark_as_changed() self._mark_as_changed()
self.hcloud_volume = None self.hcloud_volume = None