Allow to change executable (shell/interpreter) when using raw

This patch adds an optional 'executable=' option to the raw command line to override the default shell (/bin/sh), much like the shell module does.
This commit is contained in:
Dag Wieers
2012-12-23 19:17:07 +01:00
parent 3d3deb9797
commit 846161a1a4
8 changed files with 51 additions and 24 deletions

View File

@@ -81,13 +81,15 @@ class Connection(object):
os.write(self.wfd, "%s\n" % self.runner.remote_pass)
os.close(self.wfd)
def exec_command(self, cmd, tmp_path, sudo_user,sudoable=False):
def exec_command(self, cmd, tmp_path, sudo_user,sudoable=False, executable='/bin/sh'):
''' run a command on the remote host '''
ssh_cmd = self._password_cmd()
ssh_cmd += ["ssh", "-tt", "-q"] + self.common_args + [self.host]
if self.runner.sudo and sudoable:
if not self.runner.sudo or not sudoable:
ssh_cmd.append(executable + ' -c ' + pipes.quote(cmd))
else:
# Rather than detect if sudo wants a password this time, -k makes
# sudo always ask for a password if one is required.
# Passing a quoted compound command to sudo (or sudo -s)
@@ -97,10 +99,9 @@ class Connection(object):
# 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 /bin/sh -c %s' % (
prompt, sudo_user, pipes.quote(cmd))
cmd = sudocmd
ssh_cmd.append('/bin/sh -c ' + pipes.quote(cmd))
sudocmd = 'sudo -k && sudo -p "%s" -u %s %s -c %s' % (
prompt, sudo_user, executable, pipes.quote(cmd))
ssh_cmd.append('/bin/sh -c ' + pipes.quote(sudocmd))
vvv("EXEC %s" % ssh_cmd, host=self.host)
try: