diff --git a/changelogs/fragments/2159-ipa-user-sshpubkey-multi-word-comments.yaml b/changelogs/fragments/2159-ipa-user-sshpubkey-multi-word-comments.yaml new file mode 100644 index 0000000000..10547bb71b --- /dev/null +++ b/changelogs/fragments/2159-ipa-user-sshpubkey-multi-word-comments.yaml @@ -0,0 +1,2 @@ +bugfixes: + - ipa_user - allow ``sshpubkey`` to permit multiple word comments (https://github.com/ansible-collections/community.general/pull/2159). diff --git a/plugins/modules/identity/ipa/ipa_user.py b/plugins/modules/identity/ipa/ipa_user.py index fa7b3abbda..1a0c885cfb 100644 --- a/plugins/modules/identity/ipa/ipa_user.py +++ b/plugins/modules/identity/ipa/ipa_user.py @@ -269,16 +269,18 @@ def get_user_diff(client, ipa_user, module_user): def get_ssh_key_fingerprint(ssh_key, hash_algo='sha256'): """ Return the public key fingerprint of a given public SSH key - in format "[fp] [user@host] (ssh-rsa)" where fp is of the format: + in format "[fp] [comment] (ssh-rsa)" where fp is of the format: FB:0C:AC:0A:07:94:5B:CE:75:6E:63:32:13:AD:AD:D7 for md5 or SHA256:[base64] for sha256 + Comments are assumed to be all characters past the second + whitespace character in the sshpubkey string. :param ssh_key: :param hash_algo: :return: """ - parts = ssh_key.strip().split() + parts = ssh_key.strip().split(None, 2) if len(parts) == 0: return None key_type = parts[0] @@ -293,8 +295,8 @@ def get_ssh_key_fingerprint(ssh_key, hash_algo='sha256'): if len(parts) < 3: return "%s (%s)" % (key_fp, key_type) else: - user_host = parts[2] - return "%s %s (%s)" % (key_fp, user_host, key_type) + comment = parts[2] + return "%s %s (%s)" % (key_fp, comment, key_type) def ensure(module, client):