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:
parent
64c446d9c0
commit
f72b123584
1 changed files with 9 additions and 3 deletions
|
@ -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,6 +343,9 @@ 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()
|
||||||
|
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)
|
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)
|
||||||
|
@ -350,6 +353,9 @@ class Connection(ConnectionBase):
|
||||||
p = None
|
p = None
|
||||||
|
|
||||||
if not p:
|
if not p:
|
||||||
|
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)
|
p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||||
stdin = p.stdin
|
stdin = p.stdin
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue