From 80d64e7b6442cdea9d20ddf87fbdbbbae8403b8b Mon Sep 17 00:00:00 2001 From: Ajpantuso Date: Wed, 12 May 2021 10:10:08 -0400 Subject: [PATCH] openssh_keypair: Populate return values when keypair exists and check_mode=true (#230) * Swapping statement order for check_mode to initialize return values * Adding changelog fragment * Updated changelog to reflect bugfix --- .../fragments/230-openssh_keypair-check_mode-return-values.yml | 2 ++ plugins/modules/openssh_keypair.py | 3 ++- tests/integration/targets/openssh_keypair/tests/validate.yml | 1 + 3 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/230-openssh_keypair-check_mode-return-values.yml diff --git a/changelogs/fragments/230-openssh_keypair-check_mode-return-values.yml b/changelogs/fragments/230-openssh_keypair-check_mode-return-values.yml new file mode 100644 index 00000000..c52e293a --- /dev/null +++ b/changelogs/fragments/230-openssh_keypair-check_mode-return-values.yml @@ -0,0 +1,2 @@ +bugfixes: + - openssh_keypair - fix ``check_mode`` to populate return values for existing keypairs (https://github.com/ansible-collections/community.crypto/issues/113, https://github.com/ansible-collections/community.crypto/pull/230). diff --git a/plugins/modules/openssh_keypair.py b/plugins/modules/openssh_keypair.py index 69eab3c4..36225681 100644 --- a/plugins/modules/openssh_keypair.py +++ b/plugins/modules/openssh_keypair.py @@ -590,8 +590,9 @@ def main(): if keypair.state == 'present': if module.check_mode: + changed = keypair.force or not keypair.isPrivateKeyValid(module) or not keypair.isPublicKeyValid(module) result = keypair.dump() - result['changed'] = keypair.force or not keypair.isPrivateKeyValid(module) or not keypair.isPublicKeyValid(module) + result['changed'] = changed module.exit_json(**result) try: diff --git a/tests/integration/targets/openssh_keypair/tests/validate.yml b/tests/integration/targets/openssh_keypair/tests/validate.yml index cb1f05e1..ebdae6b0 100644 --- a/tests/integration/targets/openssh_keypair/tests/validate.yml +++ b/tests/integration/targets/openssh_keypair/tests/validate.yml @@ -9,6 +9,7 @@ - privatekey1_result_check is changed - privatekey1_result is changed - privatekey1_idem_result_check is not changed + - privatekey1_idem_result_check.public_key.startswith("ssh-rsa") - privatekey1_idem_result is not changed - name: Validate privatekey1 return fingerprint