From 0d5458c6cce305a76e2225416c74ba329b0245e1 Mon Sep 17 00:00:00 2001 From: Bilanda Date: Mon, 7 Dec 2020 14:59:13 +0100 Subject: [PATCH] Fix module in order to don't show "changed" status when running ansible playbook with authorized_key module if keys are not different --- plugins/modules/authorized_key.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/plugins/modules/authorized_key.py b/plugins/modules/authorized_key.py index 5f7b4b7..7b8a3f3 100644 --- a/plugins/modules/authorized_key.py +++ b/plugins/modules/authorized_key.py @@ -618,9 +618,12 @@ def enforce_state(module, params): # for 'exclusive', make sure keys are written in the order the new keys were if state == "present" and exclusive: to_remove = frozenset(existing_keys).difference(keys_to_exist) - for key in to_remove: - del existing_keys[key] - do_write = True + if len(to_remove) != 0: + for key in to_remove: + del existing_keys[key] + do_write = True + else: + do_write = False if do_write: filename = keyfile(module, user, do_write, path, manage_dir, follow)