2
0
Fork 0
mirror of https://github.com/ansible-collections/hetzner.hcloud synced 2024-12-14 06:22:32 +00:00

hcloud_server: Improve Error Message when attaching a not existing firewall ()

This commit is contained in:
Lukas Kämmerling 2021-07-16 11:37:33 +02:00 committed by GitHub
parent f4b336a444
commit ffd998a0d6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 0 deletions
changelogs/fragments
plugins/modules
tests/integration/targets/hcloud_server/tasks

View file

@ -0,0 +1,2 @@
bugfixes:
- hcloud_server Improve Error Message when attaching a not existing firewall to a server

View file

@ -476,6 +476,8 @@ class AnsibleHcloudServer(Hcloud):
self._mark_as_changed()
if not self.module.check_mode:
fw = self.client.firewalls.get_by_name(fname)
if fw is None:
self.module.fail_json(msg="firewall %s was not found" % fname)
r = FirewallResource(type="server", server=self.hcloud_server)
actions = self.client.firewalls.apply_to_resources(fw, [r])
for a in actions:

View file

@ -480,6 +480,20 @@
- main_server.hcloud_server.status == "running"
- main_server.root_password != ""
- name: test add not existing firewall should fail
hcloud_server:
name: "{{ hcloud_server_name }}"
firewalls:
- not-existing
state: present
ignore_errors: yes
register: result
- name: verifyt add not existing firewall should fail
assert:
that:
- result is failed
- 'result.msg == "firewall not-existing was not found"'
- name: test activate rescue mode with check_mode
hcloud_server:
name: "{{ hcloud_server_name }}"