Wrap all remote commands in sh

This commit is contained in:
Daniel Hokka Zakrisson 2012-11-22 20:06:30 +01:00
parent 8e515c0c94
commit ddef608c94
2 changed files with 6 additions and 6 deletions

View file

@ -125,10 +125,11 @@ class Connection(object):
prompt = '[sudo via ansible, key=%s] password: ' % randbits
sudocmd = 'sudo -k && sudo -p "%s" -u %s /bin/sh -c %s' % (
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 = ''
try:
chan.exec_command(sudocmd)
chan.exec_command(shcmd)
if self.runner.sudo_pass:
while not sudo_output.endswith(prompt):
chunk = chan.recv(bufsize)

View file

@ -93,10 +93,8 @@ class Connection(object):
prompt = '[sudo via ansible, key=%s] password: ' % randbits
sudocmd = 'sudo -k && sudo -p "%s" -u %s /bin/sh -c %s' % (
prompt, sudo_user, pipes.quote(cmd))
sudo_output = ''
ssh_cmd.append(sudocmd)
else:
ssh_cmd.append(cmd)
cmd = sudocmd
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,
@ -107,6 +105,7 @@ class Connection(object):
if self.runner.sudo and sudoable and self.runner.sudo_pass:
fcntl.fcntl(p.stdout, fcntl.F_SETFL,
fcntl.fcntl(p.stdout, fcntl.F_GETFL) | os.O_NONBLOCK)
sudo_output = ''
while not sudo_output.endswith(prompt):
rfd, wfd, efd = select.select([p.stdout], [],
[p.stdout], self.runner.timeout)