|
|
|
@ -63,6 +63,11 @@ options:
|
|
|
|
|
description:
|
|
|
|
|
- Force the assignment or deletion of the Floating IP.
|
|
|
|
|
type: bool
|
|
|
|
|
delete_protection:
|
|
|
|
|
description:
|
|
|
|
|
- Protect the Floating IP for deletion.
|
|
|
|
|
type: bool
|
|
|
|
|
version_added: "2.10"
|
|
|
|
|
labels:
|
|
|
|
|
description:
|
|
|
|
|
- User-defined labels (key-value pairs).
|
|
|
|
@ -151,6 +156,12 @@ hcloud_floating_ip:
|
|
|
|
|
type: str
|
|
|
|
|
returned: Always
|
|
|
|
|
sample: "my-server"
|
|
|
|
|
delete_protection:
|
|
|
|
|
description: True if Floating IP is protected for deletion
|
|
|
|
|
type: bool
|
|
|
|
|
returned: always
|
|
|
|
|
sample: false
|
|
|
|
|
version_added: "2.10"
|
|
|
|
|
labels:
|
|
|
|
|
description: User-defined labels (key-value pairs)
|
|
|
|
|
type: dict
|
|
|
|
@ -189,6 +200,7 @@ class AnsibleHcloudFloatingIP(Hcloud):
|
|
|
|
|
"home_location": to_native(self.hcloud_floating_ip.home_location.name),
|
|
|
|
|
"labels": self.hcloud_floating_ip.labels,
|
|
|
|
|
"server": server,
|
|
|
|
|
"delete_protection": self.hcloud_floating_ip.protection["delete"],
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
def _get_floating_ip(self):
|
|
|
|
@ -234,6 +246,7 @@ class AnsibleHcloudFloatingIP(Hcloud):
|
|
|
|
|
self._get_floating_ip()
|
|
|
|
|
|
|
|
|
|
def _update_floating_ip(self):
|
|
|
|
|
try:
|
|
|
|
|
labels = self.module.params.get("labels")
|
|
|
|
|
if labels is not None and labels != self.hcloud_floating_ip.labels:
|
|
|
|
|
if not self.module.check_mode:
|
|
|
|
@ -264,7 +277,15 @@ class AnsibleHcloudFloatingIP(Hcloud):
|
|
|
|
|
self.hcloud_floating_ip.unassign()
|
|
|
|
|
self._mark_as_changed()
|
|
|
|
|
|
|
|
|
|
delete_protection = self.module.params.get("delete_protection")
|
|
|
|
|
if delete_protection is not None and delete_protection != self.hcloud_floating_ip.protection["delete"]:
|
|
|
|
|
if not self.module.check_mode:
|
|
|
|
|
self.hcloud_floating_ip.change_protection(delete=delete_protection).wait_until_finished()
|
|
|
|
|
self._mark_as_changed()
|
|
|
|
|
|
|
|
|
|
self._get_floating_ip()
|
|
|
|
|
except APIException as e:
|
|
|
|
|
self.module.fail_json(msg=e.message)
|
|
|
|
|
|
|
|
|
|
def present_floating_ip(self):
|
|
|
|
|
self._get_floating_ip()
|
|
|
|
@ -274,6 +295,7 @@ class AnsibleHcloudFloatingIP(Hcloud):
|
|
|
|
|
self._update_floating_ip()
|
|
|
|
|
|
|
|
|
|
def delete_floating_ip(self):
|
|
|
|
|
try:
|
|
|
|
|
self._get_floating_ip()
|
|
|
|
|
if self.hcloud_floating_ip is not None:
|
|
|
|
|
if self.module.params.get("force") or self.hcloud_floating_ip.server is None:
|
|
|
|
@ -286,6 +308,8 @@ class AnsibleHcloudFloatingIP(Hcloud):
|
|
|
|
|
)
|
|
|
|
|
self._mark_as_changed()
|
|
|
|
|
self.hcloud_floating_ip = None
|
|
|
|
|
except APIException as e:
|
|
|
|
|
self.module.fail_json(msg=e.message)
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def define_module():
|
|
|
|
@ -299,6 +323,7 @@ class AnsibleHcloudFloatingIP(Hcloud):
|
|
|
|
|
force={"type": "bool"},
|
|
|
|
|
type={"choices": ["ipv4", "ipv6"]},
|
|
|
|
|
labels={"type": "dict"},
|
|
|
|
|
delete_protection={"type": "bool"},
|
|
|
|
|
state={
|
|
|
|
|
"choices": ["absent", "present"],
|
|
|
|
|
"default": "present",
|
|
|
|
|