mirror of
https://github.com/ansible-collections/hetzner.hcloud
synced 2024-12-12 21:42:35 +00:00
Fix Floating IP assignment is not idempotent (#32)
This commit is contained in:
parent
fe84174cb6
commit
e59b91ca86
3 changed files with 26 additions and 5 deletions
2
changelogs/fragments/fix-idempotency-floating-ip.yml
Normal file
2
changelogs/fragments/fix-idempotency-floating-ip.yml
Normal file
|
@ -0,0 +1,2 @@
|
|||
bugfixes:
|
||||
- hcloud_floating_ip Fix idempotency when floating ip is assigned to server
|
|
@ -259,17 +259,24 @@ class AnsibleHcloudFloatingIP(Hcloud):
|
|||
self._mark_as_changed()
|
||||
|
||||
server = self.module.params.get("server")
|
||||
if server is not None:
|
||||
if self.module.params.get("force") or self.hcloud_floating_ip.server is None:
|
||||
if server is not None and self.hcloud_floating_ip.server is not None:
|
||||
if self.module.params.get("force") and server != self.hcloud_floating_ip.server.name:
|
||||
if not self.module.check_mode:
|
||||
self.hcloud_floating_ip.assign(
|
||||
self.client.servers.get_by_name(self.module.params.get("server"))
|
||||
self.client.servers.get_by_name(server)
|
||||
)
|
||||
else:
|
||||
self._mark_as_changed()
|
||||
elif server != self.hcloud_floating_ip.server.name:
|
||||
self.module.warn(
|
||||
"Floating IP is already assigned to server %s. You need to unassign the Floating IP or use force=yes."
|
||||
"Floating IP is already assigned to another server %s. You need to unassign the Floating IP or use force=yes."
|
||||
% self.hcloud_floating_ip.server.name
|
||||
)
|
||||
self._mark_as_changed()
|
||||
elif server is not None and self.hcloud_floating_ip.server is None:
|
||||
if not self.module.check_mode:
|
||||
self.hcloud_floating_ip.assign(
|
||||
self.client.servers.get_by_name(server)
|
||||
)
|
||||
self._mark_as_changed()
|
||||
elif server is None and self.hcloud_floating_ip.server is not None:
|
||||
if not self.module.check_mode:
|
||||
|
|
|
@ -213,6 +213,18 @@
|
|||
- floatingIP is changed
|
||||
- floatingIP.hcloud_floating_ip.server == "{{ main_server.hcloud_server.name }}"
|
||||
|
||||
- name: test assign Floating IP idempotency
|
||||
hcloud_floating_ip:
|
||||
name: "{{ hcloud_floating_ip_name }}"
|
||||
description: "changed-description"
|
||||
type: ipv4
|
||||
server: "{{ main_server.hcloud_server.name }}"
|
||||
register: floatingIP
|
||||
- name: verify test unassign Floating IPidempotency
|
||||
assert:
|
||||
that:
|
||||
- floatingIP is not changed
|
||||
|
||||
- name: test unassign Floating IP
|
||||
hcloud_floating_ip:
|
||||
name: "{{ hcloud_floating_ip_name }}"
|
||||
|
|
Loading…
Reference in a new issue