mirror of
https://github.com/ansible-collections/hetzner.hcloud.git
synced 2026-02-04 08:01:49 +00:00
Merge 4cce4571c2 into 4dae1c7100
This commit is contained in:
commit
50f265fced
5 changed files with 83 additions and 0 deletions
3
changelogs/fragments/primary-ip-unassign-reassign.yml
Normal file
3
changelogs/fragments/primary-ip-unassign-reassign.yml
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
minor_changes:
|
||||||
|
- primary_ip - Unassign primary_ip if ``server`` is null.
|
||||||
|
- primary_ip - Assign to new server if ``server`` is changed.
|
||||||
|
|
@ -273,6 +273,25 @@ class AnsiblePrimaryIP(AnsibleHCloud):
|
||||||
need_reload = True
|
need_reload = True
|
||||||
self._mark_as_changed()
|
self._mark_as_changed()
|
||||||
|
|
||||||
|
if self.module.param_is_defined("server"):
|
||||||
|
if (value := self.module.params.get("server")) is not None:
|
||||||
|
server: BoundServer = self._client_get_by_name_or_id("servers", value)
|
||||||
|
server_id = server.id
|
||||||
|
if self.primary_ip.assignee_id and server_id == self.primary_ip.assignee_id:
|
||||||
|
return
|
||||||
|
if not self.module.check_mode:
|
||||||
|
action = self.primary_ip.assign(server_id, "server")
|
||||||
|
action.wait_until_finished()
|
||||||
|
self._mark_as_changed()
|
||||||
|
need_reload = True
|
||||||
|
else:
|
||||||
|
if self.primary_ip.assignee_id:
|
||||||
|
if not self.module.check_mode:
|
||||||
|
action = self.primary_ip.unassign()
|
||||||
|
action.wait_until_finished()
|
||||||
|
self._mark_as_changed()
|
||||||
|
need_reload = True
|
||||||
|
|
||||||
params = {}
|
params = {}
|
||||||
|
|
||||||
if (value := self.module.params.get("auto_delete")) is not None:
|
if (value := self.module.params.get("auto_delete")) is not None:
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,11 @@
|
||||||
name: "{{ hcloud_server_name }}"
|
name: "{{ hcloud_server_name }}"
|
||||||
state: absent
|
state: absent
|
||||||
|
|
||||||
|
- name: Cleanup test_server2
|
||||||
|
hetzner.hcloud.server:
|
||||||
|
name: "{{ hcloud_server_name }}2"
|
||||||
|
state: absent
|
||||||
|
|
||||||
- name: Cleanup test_primary_ip
|
- name: Cleanup test_primary_ip
|
||||||
hetzner.hcloud.primary_ip:
|
hetzner.hcloud.primary_ip:
|
||||||
name: "{{ hcloud_primary_ip_name }}"
|
name: "{{ hcloud_primary_ip_name }}"
|
||||||
|
|
|
||||||
|
|
@ -9,3 +9,14 @@
|
||||||
enable_ipv4: false
|
enable_ipv4: false
|
||||||
enable_ipv6: false
|
enable_ipv6: false
|
||||||
register: test_server
|
register: test_server
|
||||||
|
|
||||||
|
- name: Create test_server2
|
||||||
|
hetzner.hcloud.server:
|
||||||
|
name: "{{ hcloud_server_name }}2"
|
||||||
|
server_type: "{{ hcloud_server_type_name }}"
|
||||||
|
image: "{{ hcloud_image_name }}"
|
||||||
|
location: "{{ hcloud_location_name }}"
|
||||||
|
state: created
|
||||||
|
enable_ipv4: false
|
||||||
|
enable_ipv6: false
|
||||||
|
register: test_server2
|
||||||
|
|
|
||||||
|
|
@ -99,6 +99,25 @@
|
||||||
that:
|
that:
|
||||||
- result is not changed
|
- result is not changed
|
||||||
|
|
||||||
|
- name: Test unassign if server is null
|
||||||
|
hetzner.hcloud.primary_ip:
|
||||||
|
name: "{{ hcloud_primary_ip_name }}"
|
||||||
|
register: result
|
||||||
|
- name: Verify unassign if server is null
|
||||||
|
ansible.builtin.assert:
|
||||||
|
that:
|
||||||
|
- result is changed
|
||||||
|
- result.hcloud_primary_ip.assignee_id is none
|
||||||
|
|
||||||
|
- name: Test unassign if server is null idempotency
|
||||||
|
hetzner.hcloud.primary_ip:
|
||||||
|
name: "{{ hcloud_primary_ip_name }}"
|
||||||
|
register: result
|
||||||
|
- name: Verify unassign if server is null idempotency
|
||||||
|
ansible.builtin.assert:
|
||||||
|
that:
|
||||||
|
- result is not changed
|
||||||
|
|
||||||
- name: Test update delete protection
|
- name: Test update delete protection
|
||||||
hetzner.hcloud.primary_ip:
|
hetzner.hcloud.primary_ip:
|
||||||
name: "{{ hcloud_primary_ip_name }}"
|
name: "{{ hcloud_primary_ip_name }}"
|
||||||
|
|
@ -169,6 +188,32 @@
|
||||||
that:
|
that:
|
||||||
- result is not changed
|
- result is not changed
|
||||||
|
|
||||||
|
- name: Test assign to new server
|
||||||
|
hetzner.hcloud.primary_ip:
|
||||||
|
name: "{{ hcloud_primary_ip_name }}"
|
||||||
|
type: ipv6
|
||||||
|
server: "{{ hcloud_server_name }}2"
|
||||||
|
register: result
|
||||||
|
- name: Verify assign to new server
|
||||||
|
ansible.builtin.assert:
|
||||||
|
that:
|
||||||
|
- result is changed
|
||||||
|
- result.hcloud_primary_ip.name == hcloud_primary_ip_name
|
||||||
|
- result.hcloud_primary_ip.type == "ipv6"
|
||||||
|
- result.hcloud_primary_ip.assignee_id == test_server2.hcloud_server.id
|
||||||
|
- result.hcloud_primary_ip.assignee_type == "server"
|
||||||
|
|
||||||
|
- name: Test assign to new server idempotency
|
||||||
|
hetzner.hcloud.primary_ip:
|
||||||
|
name: "{{ hcloud_primary_ip_name }}"
|
||||||
|
type: ipv6
|
||||||
|
server: "{{ hcloud_server_name }}2"
|
||||||
|
register: result
|
||||||
|
- name: Verify assign to new server idempotency
|
||||||
|
ansible.builtin.assert:
|
||||||
|
that:
|
||||||
|
- result is not changed
|
||||||
|
|
||||||
- name: Test delete with server
|
- name: Test delete with server
|
||||||
hetzner.hcloud.primary_ip:
|
hetzner.hcloud.primary_ip:
|
||||||
name: "{{ hcloud_primary_ip_name }}"
|
name: "{{ hcloud_primary_ip_name }}"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue