summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorsbettid <davide.sbetti@gmail.com>2022-09-28 15:16:57 +0200
committerGitHub <noreply@github.com>2022-09-28 08:16:57 -0500
commit00d60a45fa7cd61b25d622735ceb4c8f6a125a76 (patch)
tree69f0744b777a88e2b9f96262f6ee66f5094806b6 /lib
parent0d188114c658c01e65a173bba83219f14e70e52f (diff)
downloadansible-00d60a45fa7cd61b25d622735ceb4c8f6a125a76.tar.gz
[stable 2.13] Fix known host changed status when removing non-existing key #78598 (#78878)
* Fix known_hosts changed status when removing non-existing key (#78748) * Ensure no change is reported when removing missing key for host with other keys Co-authored-by: Matt Martz <matt@sivel.net> * Add changelog for fix known hosts wrong changed status cherry pick * Remove old changelog for fix known hosts wrong changed status * Rename changelog according to PR number Co-authored-by: Matt Martz <matt@sivel.net>
Diffstat (limited to 'lib')
-rw-r--r--lib/ansible/modules/known_hosts.py6
1 files changed, 6 insertions, 0 deletions
diff --git a/lib/ansible/modules/known_hosts.py b/lib/ansible/modules/known_hosts.py
index ff3bf34a47..b0c888807c 100644
--- a/lib/ansible/modules/known_hosts.py
+++ b/lib/ansible/modules/known_hosts.py
@@ -143,6 +143,12 @@ def enforce_state(module, params):
params['diff'] = compute_diff(path, found_line, replace_or_add, state, key)
+ # check if we are trying to remove a non matching key,
+ # in that case return with no change to the host
+ if state == 'absent' and not found_line and key:
+ params['changed'] = False
+ return params
+
# We will change state if found==True & state!="present"
# or found==False & state=="present"
# i.e found XOR (state=="present")