From c15cffabdd93d4c472d4cc88b250445bfa971ace Mon Sep 17 00:00:00 2001 From: Rob Smith Date: Sun, 12 Jan 2014 02:12:44 -0800 Subject: [PATCH] This fixes bugs added as a part of 8665b0638a1d3a70f985126b0f007a26c81273cb 1. if accept_hostkey is false, no matter if the host key is known or not, it will fail. 2. We don't check for the host key in /etc/ssh/ssh_known_hosts This fixes both of those issues. --- lib/ansible/module_utils/known_hosts.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/lib/ansible/module_utils/known_hosts.py b/lib/ansible/module_utils/known_hosts.py index 34bc8bc7fd..b1b8affce0 100644 --- a/lib/ansible/module_utils/known_hosts.py +++ b/lib/ansible/module_utils/known_hosts.py @@ -6,12 +6,13 @@ def add_git_host_key(module, url, accept_hostkey=True): if fqdn: known_host = check_hostkey(module, fqdn) - if not known_host and accept_hostkey: - rc, out, err = add_host_key(module, fqdn) - if rc != 0: - module.fail_json(msg="failed to add %s hostkey: %s" % (fqdn, out + err)) - else: - module.fail_json(msg="%s has an unknown hostkey. Set accept_hostkey to True or manually add the hostkey prior to running the git module" % fqdn) + if not known_host: + if accept_hostkey: + rc, out, err = add_host_key(module, fqdn) + if rc != 0: + module.fail_json(msg="failed to add %s hostkey: %s" % (fqdn, out + err)) + else: + module.fail_json(msg="%s has an unknown hostkey. Set accept_hostkey to True or manually add the hostkey prior to running the git module" % fqdn) def get_fqdn(repo_url): @@ -42,6 +43,14 @@ def check_hostkey(module, fqdn): if rc == 0: if out != "": result = True + else: + # Check the main system location + this_cmd = keygen_cmd + " -H -f /etc/ssh/ssh_known_hosts -F " + fqdn + rc, out, err = module.run_command(this_cmd) + + if rc == 0: + if out != "": + result = True return result