From c7888dd6421de35cf2eb1bb6fa42c89df378c3a1 Mon Sep 17 00:00:00 2001 From: Michael DeHaan Date: Fri, 10 Aug 2012 00:15:23 -0400 Subject: [PATCH] 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. --- lib/ansible/runner/connection/paramiko_ssh.py | 7 +++---- lib/ansible/runner/connection/ssh.py | 7 +++---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/lib/ansible/runner/connection/paramiko_ssh.py b/lib/ansible/runner/connection/paramiko_ssh.py index 88e501a6cd7..7ab23b25a19 100644 --- a/lib/ansible/runner/connection/paramiko_ssh.py +++ b/lib/ansible/runner/connection/paramiko_ssh.py @@ -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 = '' diff --git a/lib/ansible/runner/connection/ssh.py b/lib/ansible/runner/connection/ssh.py index aa0b36e0772..8c84246e4ed 100644 --- a/lib/ansible/runner/connection/ssh.py +++ b/lib/ansible/runner/connection/ssh.py @@ -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)