1
0
Fork 0
mirror of https://github.com/ansible-collections/hetzner.hcloud.git synced 2026-02-04 08:01:49 +00:00

feat: add new created state for idempotent server creation (#606)

##### SUMMARY

Add a new state for server creation without immediate start, to allow
idempotent network customization before starting

##### ISSUE TYPE
- Feature Pull Request

##### COMPONENT NAME
server

---------

Co-authored-by: jo <ljonas@riseup.net>
This commit is contained in:
Daniele Fognini 2025-03-21 14:05:03 +01:00 committed by GitHub
parent 303cdeda74
commit 4534cf6b9d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
16 changed files with 68 additions and 23 deletions

View file

@ -150,7 +150,7 @@ options:
description:
- State of the server.
default: present
choices: [ absent, present, restarted, started, stopped, rebuild ]
choices: [ absent, present, created, restarted, started, stopped, rebuild ]
type: str
extends_documentation_fragment:
- hetzner.hcloud.hcloud
@ -462,7 +462,7 @@ class AnsibleHCloudServer(AnsibleHCloud):
elif self.module.params.get("location") is None and self.module.params.get("datacenter") is not None:
params["datacenter"] = self._client_get_by_name_or_id("datacenters", self.module.params.get("datacenter"))
if self.module.params.get("state") == "stopped":
if self.module.params.get("state") == "stopped" or self.module.params.get("state") == "created":
params["start_after_create"] = False
if not self.module.check_mode:
@ -944,7 +944,7 @@ class AnsibleHCloudServer(AnsibleHCloud):
rebuild_protection={"type": "bool"},
placement_group={"type": "str"},
state={
"choices": ["absent", "present", "restarted", "started", "stopped", "rebuild"],
"choices": ["absent", "present", "created", "restarted", "started", "stopped", "rebuild"],
"default": "present",
},
**super().base_module_arguments(),
@ -965,6 +965,9 @@ def main():
hcloud.delete_server()
elif state == "present":
hcloud.present_server()
hcloud.start_server()
elif state == "created":
hcloud.present_server()
elif state == "started":
hcloud.present_server()
hcloud.start_server()