Extend executable= support in raw to include no execuable

Useful for managing not-UNIX things.
This commit is contained in:
Daniel Hokka Zakrisson 2013-01-08 17:45:37 +01:00
parent 4955587d8c
commit 1b5d039bf4
4 changed files with 25 additions and 16 deletions

View file

@ -441,7 +441,7 @@ class Runner(object):
def _low_level_exec_command(self, conn, cmd, tmp, sudoable=False, executable=None):
''' execute a command string over SSH, return the output '''
if not executable:
if executable is None:
executable = '/bin/sh'
sudo_user = self.sudo_user

View file

@ -15,16 +15,11 @@
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
import os
import pwd
import random
import traceback
import tempfile
import shlex
import ansible.constants as C
from ansible import utils
from ansible import errors
from ansible import module_common
from ansible.runner.return_data import ReturnData
class ActionModule(object):
@ -36,12 +31,12 @@ class ActionModule(object):
def run(self, conn, tmp, module_name, module_args, inject):
executable = None
args = []
for arg in module_args.split(' '):
for arg in shlex.split(module_args.encode("utf-8")):
if arg.startswith('executable='):
executable = '='.join(arg.split('=')[1:])
executable = arg.split('=', 1)[1]
else:
args.append(arg)
module_args = ' '.join(args).encode('utf-8')
module_args = ' '.join(args)
return ReturnData(conn=conn,
result=self.runner._low_level_exec_command(conn, module_args, tmp, sudoable=True, executable=executable)

View file

@ -110,7 +110,10 @@ class Connection(object):
chan.get_pty()
if not self.runner.sudo or not sudoable:
quoted_command = executable + ' -c ' + pipes.quote(cmd)
if executable:
quoted_command = executable + ' -c ' + pipes.quote(cmd)
else:
quoted_command = cmd
vvv("EXEC %s" % quoted_command, host=self.host)
chan.exec_command(quoted_command)
else:
@ -123,8 +126,12 @@ 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 %s -c %s' % (
prompt, sudo_user, executable, pipes.quote(cmd))
sudocmd = 'sudo -k && sudo -p "%s" -u %s ' % (
prompt, sudo_user)
if executable:
sudocmd += "%s -c %s" % (executable, pipes.quote(cmd))
else:
sudocmd += cmd
shcmd = '/bin/sh -c ' + pipes.quote(sudocmd)
vvv("EXEC %s" % shcmd, host=self.host)
sudo_output = ''

View file

@ -88,7 +88,10 @@ class Connection(object):
ssh_cmd += ["ssh", "-tt", "-q"] + self.common_args + [self.host]
if not self.runner.sudo or not sudoable:
ssh_cmd.append(executable + ' -c ' + pipes.quote(cmd))
if executable:
ssh_cmd.append(executable + ' -c ' + pipes.quote(cmd))
else:
ssh_cmd.append(cmd)
else:
# Rather than detect if sudo wants a password this time, -k makes
# sudo always ask for a password if one is required.
@ -99,8 +102,12 @@ 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 %s -c %s' % (
prompt, sudo_user, executable, pipes.quote(cmd))
sudocmd = 'sudo -k && sudo -p "%s" -u %s ' % (
prompt, sudo_user)
if executable:
sudocmd += "%s -c %s" % (executable, pipes.quote(cmd))
else:
sudocmd += cmd
ssh_cmd.append('/bin/sh -c ' + pipes.quote(sudocmd))
vvv("EXEC %s" % ssh_cmd, host=self.host)