mirror of
https://github.com/ansible-collections/hetzner.hcloud
synced 2024-11-10 06:34:13 +00:00
hcloud_firewall: Fix race condition on deletion of firewalls (#166)
Signed-off-by: Lukas Kämmerling <lukas.kaemmerling@hetzner-cloud.de> Signed-off-by: Lukas Kämmerling <lukas.kaemmerling@hetzner-cloud.de>
This commit is contained in:
parent
123ad2c1b0
commit
6de022e9fb
2 changed files with 16 additions and 1 deletions
2
changelogs/fragments/hcloud_firewall-deletion.yml
Normal file
2
changelogs/fragments/hcloud_firewall-deletion.yml
Normal file
|
@ -0,0 +1,2 @@
|
|||
bugfixes:
|
||||
- hcloud_firewall - the deletion could fail if the firewall was referenced right before
|
|
@ -173,6 +173,7 @@ hcloud_firewall:
|
|||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils._text import to_native
|
||||
from ansible_collections.hetzner.hcloud.plugins.module_utils.hcloud import Hcloud
|
||||
import time
|
||||
|
||||
try:
|
||||
from hcloud.firewalls.domain import FirewallRule
|
||||
|
@ -293,7 +294,19 @@ class AnsibleHcloudFirewall(Hcloud):
|
|||
self._get_firewall()
|
||||
if self.hcloud_firewall is not None:
|
||||
if not self.module.check_mode:
|
||||
self.client.firewalls.delete(self.hcloud_firewall)
|
||||
retry_count = 0
|
||||
while retry_count < 10:
|
||||
try:
|
||||
self.client.firewalls.delete(self.hcloud_firewall)
|
||||
break
|
||||
except APIException as e:
|
||||
if "is still in use" in e.message:
|
||||
retry_count = retry_count + 1
|
||||
time.sleep(0.5 * retry_count)
|
||||
else:
|
||||
self.module.fail_json(msg=e.message)
|
||||
except Exception as e:
|
||||
self.module.fail_json(msg=e.message)
|
||||
self._mark_as_changed()
|
||||
self.hcloud_firewall = None
|
||||
|
||||
|
|
Loading…
Reference in a new issue