mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
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
This commit is contained in:
parent
3840119bc7
commit
4bf8071889
1 changed files with 12 additions and 2 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue