mirror of
https://github.com/ansible-collections/hetzner.hcloud
synced 2024-12-04 01:29:09 +00:00
fix: only rebuild existing servers, skip rebuild if it was just created (#581)
##### SUMMARY Fixes #580 A freshly created server must not be rebuild. ##### ISSUE TYPE - Bugfix Pull Request ##### COMPONENT NAME server
This commit is contained in:
parent
5221828cba
commit
06718d0db0
2 changed files with 20 additions and 12 deletions
2
changelogs/fragments/only-rebuild-existing-servers.yml
Normal file
2
changelogs/fragments/only-rebuild-existing-servers.yml
Normal file
|
@ -0,0 +1,2 @@
|
|||
bugfixes:
|
||||
- hcloud_server - Only rebuild existing servers, skip rebuild if the server was just created.
|
|
@ -869,18 +869,25 @@ class AnsibleHCloudServer(AnsibleHCloud):
|
|||
return None
|
||||
|
||||
def rebuild_server(self):
|
||||
self.module.fail_on_missing_params(required_params=["image"])
|
||||
try:
|
||||
if not self.module.check_mode:
|
||||
image = self._get_image(self.hcloud_server.server_type)
|
||||
resp = self.client.servers.rebuild(self.hcloud_server, image)
|
||||
# When we rebuild the server progress takes some more time.
|
||||
resp.action.wait_until_finished(max_retries=202) # 202 retries >= 1002 seconds
|
||||
self._mark_as_changed()
|
||||
self._get_server()
|
||||
if self.hcloud_server is None:
|
||||
self._create_server()
|
||||
else:
|
||||
self._update_server()
|
||||
|
||||
self._get_server()
|
||||
except HCloudException as exception:
|
||||
self.fail_json_hcloud(exception)
|
||||
# Only rebuild the server if it already existed.
|
||||
self.module.fail_on_missing_params(required_params=["image"])
|
||||
try:
|
||||
if not self.module.check_mode:
|
||||
image = self._get_image(self.hcloud_server.server_type)
|
||||
resp = self.client.servers.rebuild(self.hcloud_server, image)
|
||||
# When we rebuild the server progress takes some more time.
|
||||
resp.action.wait_until_finished(max_retries=202) # 202 retries >= 1002 seconds
|
||||
self._mark_as_changed()
|
||||
|
||||
self._get_server()
|
||||
except HCloudException as exception:
|
||||
self.fail_json_hcloud(exception)
|
||||
|
||||
def present_server(self):
|
||||
self._get_server()
|
||||
|
@ -969,7 +976,6 @@ def main():
|
|||
hcloud.stop_server()
|
||||
hcloud.start_server()
|
||||
elif state == "rebuild":
|
||||
hcloud.present_server()
|
||||
hcloud.rebuild_server()
|
||||
|
||||
module.exit_json(**hcloud.get_result())
|
||||
|
|
Loading…
Reference in a new issue