mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Merge pull request #1669 from dagwieers/ssh-tcgetattr2
Use proper pseudo-tty's instead of pipes when using subprocess
This commit is contained in:
commit
33196ec131
1 changed files with 13 additions and 4 deletions
|
@ -97,8 +97,17 @@ class Connection(object):
|
||||||
ssh_cmd.append('/bin/sh -c ' + pipes.quote(cmd))
|
ssh_cmd.append('/bin/sh -c ' + pipes.quote(cmd))
|
||||||
|
|
||||||
vvv("EXEC %s" % ssh_cmd, host=self.host)
|
vvv("EXEC %s" % ssh_cmd, host=self.host)
|
||||||
p = subprocess.Popen(ssh_cmd, stdin=subprocess.PIPE,
|
try:
|
||||||
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
# 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()
|
self._send_password()
|
||||||
|
|
||||||
|
@ -117,7 +126,7 @@ class Connection(object):
|
||||||
else:
|
else:
|
||||||
stdout = 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')
|
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)
|
||||||
|
|
||||||
# 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
|
||||||
|
@ -132,7 +141,7 @@ class Connection(object):
|
||||||
break
|
break
|
||||||
elif p.poll() is not None:
|
elif p.poll() is not None:
|
||||||
break
|
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:
|
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')
|
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')
|
||||||
|
|
Loading…
Reference in a new issue