change to STDOUT from PIPE to get ssh connection module working

This commit is contained in:
Dave Hatton 2012-06-22 12:37:23 +01:00
parent 6c37cbdae1
commit b72af8d0b9

View file

@ -76,7 +76,7 @@ class SSHConnection(object):
sudo_output = '' sudo_output = ''
ssh_cmd.append(sudocmd) ssh_cmd.append(sudocmd)
p = subprocess.Popen(ssh_cmd, stdin=subprocess.PIPE, 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: if self.runner.sudo_pass:
fcntl.fcntl(p.stdout, fcntl.F_SETFL, fcntl.fcntl(p.stdout, fcntl.F_SETFL,
fcntl.fcntl(p.stdout, fcntl.F_GETFL) | os.O_NONBLOCK) 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') raise errors.AnsibleError('ssh connection closed waiting for sudo password prompt')
sudo_output += chunk sudo_output += chunk
else: else:
(stdout, stderr) = p.communicate() stdout = p.communicate()
raise errors.AnsibleError('ssh connection error waiting for sudo password prompt') raise errors.AnsibleError('ssh connection error waiting for sudo password prompt')
p.stdin.write(self.runner.sudo_pass + '\n') 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) fcntl.fcntl(p.stdout, fcntl.F_SETFL, fcntl.fcntl(p.stdout, fcntl.F_GETFL) & ~os.O_NONBLOCK)
else: else:
ssh_cmd.append(cmd) ssh_cmd.append(cmd)
p = subprocess.Popen(ssh_cmd, stdin=subprocess.PIPE, 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 # We can't use p.communicate here because the ControlMaster may have stdout open as well
p.stdin.close() p.stdin.close()
@ -105,6 +105,8 @@ class SSHConnection(object):
rfd, wfd, efd = select.select([p.stdout], [], [p.stdout], 1) rfd, wfd, efd = select.select([p.stdout], [], [p.stdout], 1)
if p.stdout in rfd: if p.stdout in rfd:
stdout += os.read(p.stdout.fileno(), 1024) 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: 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') raise errors.AnsibleError('using -c ssh on certain older ssh versions may not support ControlPersist, set ANSIBLE_SSH_ARGS="" before running again')