Given user report that EL5 sudo does not support '--', remove it, and things seem to still work fine.

let me know if this breaks any other boxes.
This commit is contained in:
Michael DeHaan 2012-08-10 00:15:23 -04:00
parent 02ba5a48e0
commit c7888dd642
2 changed files with 6 additions and 8 deletions

View file

@ -94,16 +94,15 @@ class ParamikoConnection(object):
chan.exec_command(quoted_command)
else:
# Rather than detect if sudo wants a password this time, -k makes
# sudo always ask for a password if one is required. The "--"
# tells sudo that this is the end of sudo options and the command
# follows. Passing a quoted compound command to sudo (or sudo -s)
# sudo always ask for a password if one is required.
# Passing a quoted compound command to sudo (or sudo -s)
# directly doesn't work, so we shellquote it with pipes.quote()
# and pass the quoted string to the user's shell. We loop reading
# output until we see the randomly-generated sudo prompt set with
# the -p option.
randbits = ''.join(chr(random.randint(ord('a'), ord('z'))) for x in xrange(32))
prompt = '[sudo via ansible, key=%s] password: ' % randbits
sudocmd = 'sudo -k && sudo -p "%s" -u %s -- "$SHELL" -c %s' % (
sudocmd = 'sudo -k && sudo -p "%s" -u %s "$SHELL" -c %s' % (
prompt, sudo_user, pipes.quote(cmd))
vvv("EXEC %s" % sudocmd, host=self.host)
sudo_output = ''

View file

@ -60,16 +60,15 @@ class SSHConnection(object):
ssh_cmd = ["ssh", "-tt", "-q"] + self.common_args + [self.host]
if self.runner.sudo and sudoable:
# Rather than detect if sudo wants a password this time, -k makes
# sudo always ask for a password if one is required. The "--"
# tells sudo that this is the end of sudo options and the command
# follows. Passing a quoted compound command to sudo (or sudo -s)
# sudo always ask for a password if one is required.
# Passing a quoted compound command to sudo (or sudo -s)
# directly doesn't work, so we shellquote it with pipes.quote()
# and pass the quoted string to the user's shell. We loop reading
# output until we see the randomly-generated sudo prompt set with
# the -p option.
randbits = ''.join(chr(random.randint(ord('a'), ord('z'))) for x in xrange(32))
prompt = '[sudo via ansible, key=%s] password: ' % randbits
sudocmd = 'sudo -k && sudo -p "%s" -u %s -- "$SHELL" -c %s' % (
sudocmd = 'sudo -k && sudo -p "%s" -u %s "$SHELL" -c %s' % (
prompt, sudo_user, pipes.quote(cmd))
sudo_output = ''
ssh_cmd.append(sudocmd)