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