From d0e37aeec1b4b1287749088813df4d9b230cb0a7 Mon Sep 17 00:00:00 2001 From: Sam Doran Date: Fri, 17 Jul 2020 15:40:38 -0400 Subject: [PATCH] [stable-2.10] Improve error message when ssh client is not found on the host (#70122) (#70386) * Add changlelog (cherry picked from commit 70bb2b33ca) Co-authored-by: Mykola Grygoriev Co-authored-by: Mykola Grygoriev --- ...ve-error-message-ssh-client-is-not-found.yml | 2 ++ lib/ansible/plugins/connection/ssh.py | 17 +++++++++++------ 2 files changed, 13 insertions(+), 6 deletions(-) create mode 100644 changelogs/fragments/70122-improve-error-message-ssh-client-is-not-found.yml diff --git a/changelogs/fragments/70122-improve-error-message-ssh-client-is-not-found.yml b/changelogs/fragments/70122-improve-error-message-ssh-client-is-not-found.yml new file mode 100644 index 00000000000..cd60ca3f93e --- /dev/null +++ b/changelogs/fragments/70122-improve-error-message-ssh-client-is-not-found.yml @@ -0,0 +1,2 @@ +bugfixes: + - SSH plugin - Improve error message when ssh client is not found on the host diff --git a/lib/ansible/plugins/connection/ssh.py b/lib/ansible/plugins/connection/ssh.py index 222703d7009..924604421b1 100644 --- a/lib/ansible/plugins/connection/ssh.py +++ b/lib/ansible/plugins/connection/ssh.py @@ -818,12 +818,17 @@ class Connection(ConnectionBase): p = None if not p: - if PY3 and conn_password: - # pylint: disable=unexpected-keyword-arg - p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, pass_fds=self.sshpass_pipe) - else: - p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - stdin = p.stdin + try: + if PY3 and conn_password: + # pylint: disable=unexpected-keyword-arg + p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, + stderr=subprocess.PIPE, pass_fds=self.sshpass_pipe) + else: + p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + stdin = p.stdin + except (OSError, IOError) as e: + raise AnsibleError('Unable to execute ssh command line on a controller due to: %s' % to_native(e)) # If we are using SSH password authentication, write the password into # the pipe we opened in _build_command.