hcloud_rdns improve error message on not existing server/Floating IP (#99)

Signed-off-by: Lukas Kämmerling <lukas.kaemmerling@hetzner-cloud.de>
This commit is contained in:
Lukas Kämmerling 2021-07-22 09:24:11 +02:00 committed by GitHub
parent 9b1492a32c
commit 2be9ff3240
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 1 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- hcloud_rdns improve error message on not existing server/Floating IP

View file

@ -143,10 +143,14 @@ class AnsibleHcloudReverseDNS(Hcloud):
self.hcloud_resource = self.client.servers.get_by_name(
self.module.params.get("server")
)
if self.hcloud_resource is None:
self.module.fail_json(msg="The selected server does not exist")
elif self.module.params.get("floating_ip"):
self.hcloud_resource = self.client.floating_ips.get_by_name(
self.module.params.get("floating_ip")
)
if self.hcloud_resource is None:
self.module.fail_json(msg="The selected Floating IP does not exist")
except Exception as e:
self.module.fail_json(msg=e.message)

View file

@ -36,7 +36,18 @@
that:
- result is failed
- 'result.msg == "missing required arguments: ip_address"'
- name: test fail on not existing resource
hcloud_rdns:
server: "not-existing"
ip_address: "127.0.0.1"
state: present
register: result
ignore_errors: yes
- name: verify fail on not existing resou
assert:
that:
- result is failed
- 'result.msg == "The selected server does not exist"'
- name: test create rdns
hcloud_rdns:
server: "{{ hcloud_server_name }}"