summaryrefslogtreecommitdiff
path: root/lib/ansible
diff options
context:
space:
mode:
authorMichael DeHaan <michael.dehaan@gmail.com>2012-11-24 08:30:26 -0800
committerMichael DeHaan <michael.dehaan@gmail.com>2012-11-24 08:30:26 -0800
commit33196ec131abaa7b420de615c078d415cc6cd917 (patch)
treeb0c4a116e96a229f5400da692369f25459a1b44b /lib/ansible
parentac09b47ec4687bf66ba3c090c1251cf37f3b5b56 (diff)
parent7192eb30477f8987836c075eece6e530eb9b07f2 (diff)
downloadansible-33196ec131abaa7b420de615c078d415cc6cd917.tar.gz
Merge pull request #1669 from dagwieers/ssh-tcgetattr2
Use proper pseudo-tty's instead of pipes when using subprocess
Diffstat (limited to 'lib/ansible')
-rw-r--r--lib/ansible/runner/connection_plugins/ssh.py17
1 files changed, 13 insertions, 4 deletions
diff --git a/lib/ansible/runner/connection_plugins/ssh.py b/lib/ansible/runner/connection_plugins/ssh.py
index 5a33774bbc..1537f950c5 100644
--- a/lib/ansible/runner/connection_plugins/ssh.py
+++ b/lib/ansible/runner/connection_plugins/ssh.py
@@ -97,8 +97,17 @@ class Connection(object):
ssh_cmd.append('/bin/sh -c ' + pipes.quote(cmd))
vvv("EXEC %s" % ssh_cmd, host=self.host)
- p = subprocess.Popen(ssh_cmd, stdin=subprocess.PIPE,
- stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
+ try:
+ # Make sure stdin is a proper (pseudo) pty to avoid: tcgetattr errors
+ import pty
+ master, slave = pty.openpty()
+ p = subprocess.Popen(ssh_cmd, stdin=slave,
+ stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
+ stdin = os.fdopen(master, 'w', 0)
+ except:
+ p = subprocess.Popen(ssh_cmd, stdin=subprocess.PIPE,
+ stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
+ stdin = p.stdin
self._send_password()
@@ -117,7 +126,7 @@ class Connection(object):
else:
stdout = p.communicate()
raise errors.AnsibleError('ssh connection error waiting for sudo password prompt')
- p.stdin.write(self.runner.sudo_pass + '\n')
+ stdin.write(self.runner.sudo_pass + '\n')
fcntl.fcntl(p.stdout, fcntl.F_SETFL, fcntl.fcntl(p.stdout, fcntl.F_GETFL) & ~os.O_NONBLOCK)
# We can't use p.communicate here because the ControlMaster may have stdout open as well
@@ -132,7 +141,7 @@ class Connection(object):
break
elif p.poll() is not None:
break
- p.stdin.close() # close stdin after we read from stdout (see also issue #848)
+ stdin.close() # close stdin after we read from stdout (see also issue #848)
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="" (or ansible_ssh_args in the config file) before running again')