1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

On python3, subprocess needs another arg to pass extra file descriptors

This commit is contained in:
Toshio Kuratomi 2016-10-02 15:04:38 -07:00
parent 64c446d9c0
commit f72b123584

View file

@ -29,7 +29,7 @@ import subprocess
import time import time
from ansible import constants as C from ansible import constants as C
from ansible.compat.six import text_type, binary_type from ansible.compat.six import PY3, text_type, binary_type
from ansible.errors import AnsibleError, AnsibleConnectionFailure, AnsibleFileNotFound from ansible.errors import AnsibleError, AnsibleConnectionFailure, AnsibleFileNotFound
from ansible.errors import AnsibleOptionsError from ansible.errors import AnsibleOptionsError
from ansible.module_utils.basic import BOOLEANS from ansible.module_utils.basic import BOOLEANS
@ -343,14 +343,20 @@ class Connection(ConnectionBase):
try: try:
# Make sure stdin is a proper pty to avoid tcgetattr errors # Make sure stdin is a proper pty to avoid tcgetattr errors
master, slave = pty.openpty() master, slave = pty.openpty()
p = subprocess.Popen(cmd, stdin=slave, stdout=subprocess.PIPE, stderr=subprocess.PIPE) if PY3 and self._play_context.password:
p = subprocess.Popen(cmd, stdin=slave, stdout=subprocess.PIPE, stderr=subprocess.PIPE, pass_fds=self.sshpass_pipe)
else:
p = subprocess.Popen(cmd, stdin=slave, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdin = os.fdopen(master, 'wb', 0) stdin = os.fdopen(master, 'wb', 0)
os.close(slave) os.close(slave)
except (OSError, IOError): except (OSError, IOError):
p = None p = None
if not p: if not p:
p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) if PY3 and self._play_context.password:
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 stdin = p.stdin
# If we are using SSH password authentication, write the password into # If we are using SSH password authentication, write the password into