Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix boot ssh key setting #33

Merged
merged 10 commits into from
Jan 4, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/33-fix-boot-ssh-key-setting.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- bugfix for incorrect handling of ssh-keys for the community.hcloud.boot module. Trying to set the boot record with the module lets the API return errors (reported in https://github.com/ansible-collections/community.hrobot/issues/32). This is and the idempotence for ssh-keys is fixed with the https://github.com/ansible-collections/community.hrobot/pull/33 MR.
This conversation was marked as resolved.
Show resolved Hide resolved
14 changes: 11 additions & 3 deletions plugins/modules/boot.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,15 +384,23 @@ def main():
option = module.params[option_name][option_key]
if option is None or option == []:
continue
data[data_key] = option

if isinstance(option, list):
data[data_key+'[]'] = option
felixfontein marked this conversation as resolved.
Show resolved Hide resolved
else:
data[data_key] = option
felixfontein marked this conversation as resolved.
Show resolved Hide resolved
if existing.get('active'):
# Idempotence check
needs_change = False
for option_key, (result_key, data_key) in options.items():
should = module.params[option_name][option_key]
if should is None:
continue
has = existing.get(data_key)
# unfold the return object for the idempotence check to work correctly
if option_key == 'authorized_keys':
has = list(map(lambda x: x['key']['fingerprint'], existing.get(data_key)))
else:
has = existing.get(data_key)
felixfontein marked this conversation as resolved.
Show resolved Hide resolved
if isinstance(has, list):
has = sorted(has)
if not isinstance(should, list):
Expand All @@ -415,7 +423,7 @@ def main():
result, dummy = fetch_url_json(
module,
url,
data=urlencode(data),
data=urlencode(data, True),
headers=headers,
method='POST',
)
Expand Down