From 0b64408f5a2d2135afcb68988c51a3dd50e0124f Mon Sep 17 00:00:00 2001 From: James Tanner Date: Wed, 8 Jan 2014 16:50:40 -0500 Subject: [PATCH] Fixes #5531 Give the user a better error message when sshpass does not know the remote hostkey --- lib/ansible/runner/connection_plugins/ssh.py | 5 +++++ lib/ansible/runner/connection_plugins/ssh_alt.py | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/lib/ansible/runner/connection_plugins/ssh.py b/lib/ansible/runner/connection_plugins/ssh.py index 3da15de6753..43cd1b1b634 100644 --- a/lib/ansible/runner/connection_plugins/ssh.py +++ b/lib/ansible/runner/connection_plugins/ssh.py @@ -255,6 +255,11 @@ class Connection(object): # the host to known hosts is not intermingled with multiprocess output. fcntl.lockf(self.runner.output_lockfile, fcntl.LOCK_UN) fcntl.lockf(self.runner.process_lockfile, fcntl.LOCK_UN) + + if C.HOST_KEY_CHECKING: + if ssh_cmd[0] == "sshpass" and p.returncode == 6: + raise errors.AnsibleError('sshpass has exited with error 6. This is typically caused by combining host_key_checking=True and --ask-pass without first adding the hostkey to known_hosts.') + controlpersisterror = stderr.find('Bad configuration option: ControlPersist') != -1 or stderr.find('unknown configuration option: ControlPersist') != -1 if p.returncode != 0 and controlpersisterror: raise errors.AnsibleError('using -c ssh on certain older ssh versions may not support ControlPersist, set ANSIBLE_SSH_ARGS="" (or ansible_ssh_args in the config file) before running again') diff --git a/lib/ansible/runner/connection_plugins/ssh_alt.py b/lib/ansible/runner/connection_plugins/ssh_alt.py index 1f9fb04bd56..7608c0f91be 100644 --- a/lib/ansible/runner/connection_plugins/ssh_alt.py +++ b/lib/ansible/runner/connection_plugins/ssh_alt.py @@ -294,6 +294,11 @@ class Connection(object): fcntl.lockf(self.runner.output_lockfile, fcntl.LOCK_UN) fcntl.lockf(self.runner.process_lockfile, fcntl.LOCK_UN) controlpersisterror = stderr.find('Bad configuration option: ControlPersist') != -1 or stderr.find('unknown configuration option: ControlPersist') != -1 + + if C.HOST_KEY_CHECKING: + if ssh_cmd[0] == "sshpass" and p.returncode == 6: + raise errors.AnsibleError('sshpass has exited with error 6. This is typically caused by combining host_key_checking=True and --ask-pass without first adding the hostkey to known_hosts.') + if p.returncode != 0 and controlpersisterror: raise errors.AnsibleError('using -c ssh on certain older ssh versions may not support ControlPersist, set ANSIBLE_SSH_ARGS="" (or ansible_ssh_args in the config file) before running again') if p.returncode == 255 and in_data: