mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Wrap all remote commands in sh
This commit is contained in:
parent
8e515c0c94
commit
ddef608c94
2 changed files with 6 additions and 6 deletions
|
@ -125,10 +125,11 @@ class Connection(object):
|
||||||
prompt = '[sudo via ansible, key=%s] password: ' % randbits
|
prompt = '[sudo via ansible, key=%s] password: ' % randbits
|
||||||
sudocmd = 'sudo -k && sudo -p "%s" -u %s /bin/sh -c %s' % (
|
sudocmd = 'sudo -k && sudo -p "%s" -u %s /bin/sh -c %s' % (
|
||||||
prompt, sudo_user, pipes.quote(cmd))
|
prompt, sudo_user, pipes.quote(cmd))
|
||||||
vvv("EXEC %s" % sudocmd, host=self.host)
|
shcmd = '/bin/sh -c ' + pipes.quote(sudocmd)
|
||||||
|
vvv("EXEC %s" % shcmd, host=self.host)
|
||||||
sudo_output = ''
|
sudo_output = ''
|
||||||
try:
|
try:
|
||||||
chan.exec_command(sudocmd)
|
chan.exec_command(shcmd)
|
||||||
if self.runner.sudo_pass:
|
if self.runner.sudo_pass:
|
||||||
while not sudo_output.endswith(prompt):
|
while not sudo_output.endswith(prompt):
|
||||||
chunk = chan.recv(bufsize)
|
chunk = chan.recv(bufsize)
|
||||||
|
|
|
@ -93,10 +93,8 @@ class Connection(object):
|
||||||
prompt = '[sudo via ansible, key=%s] password: ' % randbits
|
prompt = '[sudo via ansible, key=%s] password: ' % randbits
|
||||||
sudocmd = 'sudo -k && sudo -p "%s" -u %s /bin/sh -c %s' % (
|
sudocmd = 'sudo -k && sudo -p "%s" -u %s /bin/sh -c %s' % (
|
||||||
prompt, sudo_user, pipes.quote(cmd))
|
prompt, sudo_user, pipes.quote(cmd))
|
||||||
sudo_output = ''
|
cmd = sudocmd
|
||||||
ssh_cmd.append(sudocmd)
|
ssh_cmd.append('/bin/sh -c ' + pipes.quote(cmd))
|
||||||
else:
|
|
||||||
ssh_cmd.append(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,
|
p = subprocess.Popen(ssh_cmd, stdin=subprocess.PIPE,
|
||||||
|
@ -107,6 +105,7 @@ class Connection(object):
|
||||||
if self.runner.sudo and sudoable and self.runner.sudo_pass:
|
if self.runner.sudo and sudoable and 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)
|
||||||
|
sudo_output = ''
|
||||||
while not sudo_output.endswith(prompt):
|
while not sudo_output.endswith(prompt):
|
||||||
rfd, wfd, efd = select.select([p.stdout], [],
|
rfd, wfd, efd = select.select([p.stdout], [],
|
||||||
[p.stdout], self.runner.timeout)
|
[p.stdout], self.runner.timeout)
|
||||||
|
|
Loading…
Reference in a new issue