From d42df3a82ed1a27884b91b0f17ec1c0df4b28b65 Mon Sep 17 00:00:00 2001 From: Dave Hatton Date: Fri, 22 Jun 2012 12:37:23 +0100 Subject: [PATCH] change to STDOUT from PIPE to get ssh connection module working --- lib/ansible/runner/connection/ssh.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/ansible/runner/connection/ssh.py b/lib/ansible/runner/connection/ssh.py index 7224033a52b..9f9c8c476f9 100644 --- a/lib/ansible/runner/connection/ssh.py +++ b/lib/ansible/runner/connection/ssh.py @@ -76,7 +76,7 @@ class SSHConnection(object): sudo_output = '' ssh_cmd.append(sudocmd) p = subprocess.Popen(ssh_cmd, stdin=subprocess.PIPE, - stdout=subprocess.PIPE, stderr=subprocess.PIPE) + stdout=subprocess.PIPE, stderr=subprocess.STDOUT) if self.runner.sudo_pass: fcntl.fcntl(p.stdout, fcntl.F_SETFL, fcntl.fcntl(p.stdout, fcntl.F_GETFL) | os.O_NONBLOCK) @@ -89,14 +89,14 @@ class SSHConnection(object): raise errors.AnsibleError('ssh connection closed waiting for sudo password prompt') sudo_output += chunk else: - (stdout, stderr) = p.communicate() + stdout = p.communicate() raise errors.AnsibleError('ssh connection error waiting for sudo password prompt') p.stdin.write(self.runner.sudo_pass + '\n') fcntl.fcntl(p.stdout, fcntl.F_SETFL, fcntl.fcntl(p.stdout, fcntl.F_GETFL) & ~os.O_NONBLOCK) else: ssh_cmd.append(cmd) p = subprocess.Popen(ssh_cmd, stdin=subprocess.PIPE, - stdout=subprocess.PIPE, stderr=subprocess.PIPE) + stdout=subprocess.PIPE, stderr=subprocess.STDOUT) # We can't use p.communicate here because the ControlMaster may have stdout open as well p.stdin.close() @@ -105,6 +105,8 @@ class SSHConnection(object): rfd, wfd, efd = select.select([p.stdout], [], [p.stdout], 1) if p.stdout in rfd: stdout += os.read(p.stdout.fileno(), 1024) + # older versions of ssh generate this error which we ignore + stdout=stdout.replace("tcgetattr: Invalid argument\n", "") if p.returncode != 0 and stdout.find('Bad configuration option: ControlPersist') != -1: raise errors.AnsibleError('using -c ssh on certain older ssh versions may not support ControlPersist, set ANSIBLE_SSH_ARGS="" before running again')