From 4bf807188921850f2349d16c3c2b060ca134ab06 Mon Sep 17 00:00:00 2001 From: Toshio Kuratomi Date: Fri, 5 May 2017 08:17:00 -0700 Subject: [PATCH] Give user whatever information we have from ssh-keyscan ssh-keyscan isn't very verbose about errors. Give the user whatever information we have available even if it isn't much. At least they will know how we were running ssh-keyscan and why there's an error now. Fixes #19440 --- lib/ansible/module_utils/known_hosts.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/ansible/module_utils/known_hosts.py b/lib/ansible/module_utils/known_hosts.py index de43b81149..1e5d27856b 100644 --- a/lib/ansible/module_utils/known_hosts.py +++ b/lib/ansible/module_utils/known_hosts.py @@ -200,9 +200,19 @@ def add_host_key(module, fqdn, port=22, key_type="rsa", create_dir=False): this_cmd = "%s -t %s %s" % (keyscan_cmd, key_type, fqdn) rc, out, err = module.run_command(this_cmd) - # ssh-keyscan gives a 0 exit code and prints nothins on timeout + # ssh-keyscan gives a 0 exit code and prints nothing on timeout if rc != 0 or not out: - module.fail_json(msg='failed to get the hostkey for %s' % fqdn) + msg = 'failed to retrieve hostkey' + if not out: + msg += '. "%s" returned no matches.' % this_cmd + else: + msg += ' using command "%s". [stdout]: %s' % (this_cmd, out) + + if err: + msg += ' [stderr]: %s' % err + + module.fail_json(msg=msg) + module.append_to_file(user_host_file, out) return rc, out, err