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:
Jonas L. 2024-11-11 17:09:37 +01:00 committed by GitHub
parent 5221828cba
commit 06718d0db0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 20 additions and 12 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- hcloud_server - Only rebuild existing servers, skip rebuild if the server was just created.

View file

@ -869,6 +869,13 @@ class AnsibleHCloudServer(AnsibleHCloud):
return None
def rebuild_server(self):
self._get_server()
if self.hcloud_server is None:
self._create_server()
else:
self._update_server()
# Only rebuild the server if it already existed.
self.module.fail_on_missing_params(required_params=["image"])
try:
if not self.module.check_mode:
@ -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())