hcloud_server: fix traceback in check mode (#64)

* hcloud_server: fix traceback in check mode 

if server not exists.

* add changelog
This commit is contained in:
René Moser 2021-03-12 14:22:47 +01:00 committed by GitHub
parent 3621a52687
commit 5b0837d159
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 10 deletions

View file

View file

@ -0,0 +1,2 @@
bugfixes:
- hcloud_server - fix a crash related to check mode if ``state=started`` or ``state=stopped`` (https://github.com/ansible-collections/hetzner.hcloud/issues/54).

View file

@ -500,21 +500,23 @@ class AnsibleHcloudServer(Hcloud):
def start_server(self):
try:
if self.hcloud_server.status != Server.STATUS_RUNNING:
if not self.module.check_mode:
self.client.servers.power_on(self.hcloud_server).wait_until_finished()
self._mark_as_changed()
self._get_server()
if self.hcloud_server:
if self.hcloud_server.status != Server.STATUS_RUNNING:
if not self.module.check_mode:
self.client.servers.power_on(self.hcloud_server).wait_until_finished()
self._mark_as_changed()
self._get_server()
except Exception as e:
self.module.fail_json(msg=e.message)
def stop_server(self):
try:
if self.hcloud_server.status != Server.STATUS_OFF:
if not self.module.check_mode:
self.client.servers.power_off(self.hcloud_server).wait_until_finished()
self._mark_as_changed()
self._get_server()
if self.hcloud_server:
if self.hcloud_server.status != Server.STATUS_OFF:
if not self.module.check_mode:
self.client.servers.power_off(self.hcloud_server).wait_until_finished()
self._mark_as_changed()
self._get_server()
except Exception as e:
self.module.fail_json(msg=e.message)