mirror of
https://github.com/ansible-collections/hetzner.hcloud.git
synced 2026-02-04 08:01:49 +00:00
fix: unassign primary ip and floating ip before deletion (#796)
##### SUMMARY Explicitly unassign Primary IP and Floating IPs before deleting them. This allows us to better handle any errors that happen during the unassign and is consistent with the flow in our Terraform provider. ##### ISSUE TYPE - Bugfix Pull Request ##### COMPONENT NAME <!--- Write the short name of the module, plugin, task or feature below --> - `floating_ip` - `primary_ip` --------- Co-authored-by: jo <ljonas@riseup.net>
This commit is contained in:
parent
ecf2b2b00d
commit
241f61338b
3 changed files with 31 additions and 11 deletions
|
|
@ -281,16 +281,24 @@ class AnsibleFloatingIP(AnsibleHCloud):
|
|||
self.floating_ip = self.floating_ip.update(**params)
|
||||
|
||||
def _delete(self):
|
||||
if self.module.params.get("force") or self.floating_ip.server is None:
|
||||
if self.floating_ip.server is not None:
|
||||
if self.module.params.get("force"):
|
||||
if not self.module.check_mode:
|
||||
action = self.floating_ip.unassign()
|
||||
action.wait_until_finished()
|
||||
|
||||
self.floating_ip.delete()
|
||||
self._mark_as_changed()
|
||||
else:
|
||||
self.module.warn(
|
||||
"Floating IP is currently assigned to server "
|
||||
f"{self.floating_ip.server.name}. You need to "
|
||||
"unassign the Floating IP or use force=true."
|
||||
)
|
||||
else:
|
||||
if not self.module.check_mode:
|
||||
self.floating_ip.delete()
|
||||
self._mark_as_changed()
|
||||
else:
|
||||
self.module.warn(
|
||||
"Floating IP is currently assigned to server "
|
||||
f"{self.floating_ip.server.name}. You need to "
|
||||
"unassign the Floating IP or use force=true."
|
||||
)
|
||||
|
||||
self.floating_ip = None
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue