mirror of
https://github.com/ansible-collections/hetzner.hcloud.git
synced 2026-02-04 08:01:49 +00:00
refactor: Check idempotency for re-create key with force option
This commit is contained in:
parent
58f6b00d68
commit
9aa94c643c
1 changed files with 9 additions and 5 deletions
|
|
@ -130,6 +130,7 @@ from ansible.module_utils.basic import AnsibleModule
|
|||
from ..module_utils.hcloud import AnsibleHCloud
|
||||
from ..module_utils.vendor.hcloud import HCloudException
|
||||
from ..module_utils.vendor.hcloud.ssh_keys import BoundSSHKey
|
||||
from ..module_utils.ssh import ssh_public_key_md5_fingerprint
|
||||
|
||||
|
||||
class AnsibleHCloudSSHKey(AnsibleHCloud):
|
||||
|
|
@ -189,11 +190,14 @@ class AnsibleHCloudSSHKey(AnsibleHCloud):
|
|||
self._mark_as_changed()
|
||||
|
||||
force = self.module.params.get("force")
|
||||
if force is not None and force:
|
||||
if not self.module.check_mode:
|
||||
self.hcloud_ssh_key.delete()
|
||||
self._create_ssh_key()
|
||||
self._mark_as_changed()
|
||||
public_key = self.module.params.get("public_key")
|
||||
if force is not None and public_key is not None and force:
|
||||
fingerprint = ssh_public_key_md5_fingerprint(public_key)
|
||||
if fingerprint != self.hcloud_ssh_key.fingerprint:
|
||||
if not self.module.check_mode:
|
||||
self.hcloud_ssh_key.delete()
|
||||
self._create_ssh_key()
|
||||
self._mark_as_changed()
|
||||
self._get_ssh_key()
|
||||
|
||||
def present_ssh_key(self):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue