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

reset password

This commit is contained in:
jo 2025-12-03 14:17:49 +01:00
parent c5809b6892
commit 932ae82f79
No known key found for this signature in database
GPG key ID: B2FEC9B22722B984

View file

@ -123,8 +123,9 @@ options:
state:
description:
- State of the Storage Box.
- C(reset_password) is not idempotent.
default: present
choices: [absent, present]
choices: [absent, present, reset_password]
type: str
extends_documentation_fragment:
@ -432,8 +433,6 @@ class AnsibleStorageBox(AnsibleHCloud):
self.actions.append(action)
self._mark_as_changed()
# self.storage_box.reset_password
params = {}
if (value := self.module.params.get("name")) is not None and value != self.storage_box.name:
self.fail_on_invalid_params(required=["id"])
@ -481,6 +480,24 @@ class AnsibleStorageBox(AnsibleHCloud):
except HCloudException as exception:
self.fail_json_hcloud(exception)
def reset_password(self):
self.fail_on_invalid_params(
required=["password"],
)
try:
self._fetch()
if self.storage_box is None:
self._create()
else:
if not self.module.check_mode:
action = self.storage_box.reset_password(self.module.params.get("password"))
self.actions.append(action)
self._mark_as_changed()
self._update()
except HCloudException as exception:
self.fail_json_hcloud(exception)
@classmethod
def define_module(cls):
return AnsibleModule(
@ -514,7 +531,7 @@ class AnsibleStorageBox(AnsibleHCloud):
},
delete_protection={"type": "bool"},
state={
"choices": ["absent", "present"],
"choices": ["absent", "present", "reset_password"],
"default": "present",
},
**super().base_module_arguments(),
@ -531,6 +548,8 @@ def main():
state = module.params.get("state")
if state == "absent":
o.absent()
elif state == "reset_password":
o.reset_password()
else:
o.present()