mirror of
https://github.com/ansible-collections/hetzner.hcloud
synced 2024-11-10 06:34:13 +00:00
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:
parent
3621a52687
commit
5b0837d159
3 changed files with 14 additions and 10 deletions
0
changelogs/fragments/.keep
Normal file
0
changelogs/fragments/.keep
Normal 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).
|
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in a new issue