mirror of
https://github.com/ansible-collections/hetzner.hcloud
synced 2024-12-05 01:59:14 +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,6 +869,13 @@ class AnsibleHCloudServer(AnsibleHCloud):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def rebuild_server(self):
|
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"])
|
self.module.fail_on_missing_params(required_params=["image"])
|
||||||
try:
|
try:
|
||||||
if not self.module.check_mode:
|
if not self.module.check_mode:
|
||||||
|
@ -969,7 +976,6 @@ def main():
|
||||||
hcloud.stop_server()
|
hcloud.stop_server()
|
||||||
hcloud.start_server()
|
hcloud.start_server()
|
||||||
elif state == "rebuild":
|
elif state == "rebuild":
|
||||||
hcloud.present_server()
|
|
||||||
hcloud.rebuild_server()
|
hcloud.rebuild_server()
|
||||||
|
|
||||||
module.exit_json(**hcloud.get_result())
|
module.exit_json(**hcloud.get_result())
|
||||||
|
|
Loading…
Reference in a new issue