From 3ec043ec177d6ac5187f43052e34357890196315 Mon Sep 17 00:00:00 2001 From: James Tanner Date: Tue, 28 Jan 2014 11:49:35 -0500 Subject: [PATCH] Fixes #5750 Fail on missing ~/.ssh and ignore accept_hostkey if stricthoskeychecking is off --- lib/ansible/module_utils/known_hosts.py | 4 ++++ library/source_control/git | 9 +++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/ansible/module_utils/known_hosts.py b/lib/ansible/module_utils/known_hosts.py index 0fa55774c4..000db9d1e6 100644 --- a/lib/ansible/module_utils/known_hosts.py +++ b/lib/ansible/module_utils/known_hosts.py @@ -59,6 +59,10 @@ def add_host_key(module, fqdn, key_type="rsa"): result = False keyscan_cmd = module.get_bin_path('ssh-keyscan', True) + + if not os.path.exists(os.path.expanduser("~/.ssh/")): + module.fail_json(msg="%s does not exist" % os.path.expanduser("~/.ssh/")) + this_cmd = "%s -t %s %s >> ~/.ssh/known_hosts" % (keyscan_cmd, key_type, fqdn) rc, out, err = module.run_command(this_cmd) diff --git a/library/source_control/git b/library/source_control/git index b769776a3a..768e315788 100644 --- a/library/source_control/git +++ b/library/source_control/git @@ -49,6 +49,8 @@ options: version_added: "1.5" description: - Add the hostkey for the repo url if not already added. + If ssh_args contains "-o StrictHostKeyChecking=no", this + parameter is ignored. ssh_opts: required: false default: None @@ -445,8 +447,11 @@ def main(): set_git_ssh(ssh_wrapper, key_file, ssh_opts) # add the git repo's hostkey - #if module.params['accept_hostkey']: - add_git_host_key(module, repo, accept_hostkey=module.params['accept_hostkey']) + if module.params['ssh_opts'] is not None: + if not "-o StrictHostKeyChecking=no" in module.params['ssh_opts']: + add_git_host_key(module, repo, accept_hostkey=module.params['accept_hostkey']) + else: + add_git_host_key(module, repo, accept_hostkey=module.params['accept_hostkey']) if bare: gitconfig = os.path.join(dest, 'config')