mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Extend executable= support in raw to include no execuable
Useful for managing not-UNIX things.
This commit is contained in:
parent
4955587d8c
commit
1b5d039bf4
4 changed files with 25 additions and 16 deletions
|
@ -441,7 +441,7 @@ class Runner(object):
|
||||||
def _low_level_exec_command(self, conn, cmd, tmp, sudoable=False, executable=None):
|
def _low_level_exec_command(self, conn, cmd, tmp, sudoable=False, executable=None):
|
||||||
''' execute a command string over SSH, return the output '''
|
''' execute a command string over SSH, return the output '''
|
||||||
|
|
||||||
if not executable:
|
if executable is None:
|
||||||
executable = '/bin/sh'
|
executable = '/bin/sh'
|
||||||
|
|
||||||
sudo_user = self.sudo_user
|
sudo_user = self.sudo_user
|
||||||
|
|
|
@ -15,16 +15,11 @@
|
||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import os
|
import shlex
|
||||||
import pwd
|
|
||||||
import random
|
|
||||||
import traceback
|
|
||||||
import tempfile
|
|
||||||
|
|
||||||
import ansible.constants as C
|
import ansible.constants as C
|
||||||
from ansible import utils
|
from ansible import utils
|
||||||
from ansible import errors
|
from ansible import errors
|
||||||
from ansible import module_common
|
|
||||||
from ansible.runner.return_data import ReturnData
|
from ansible.runner.return_data import ReturnData
|
||||||
|
|
||||||
class ActionModule(object):
|
class ActionModule(object):
|
||||||
|
@ -36,12 +31,12 @@ class ActionModule(object):
|
||||||
def run(self, conn, tmp, module_name, module_args, inject):
|
def run(self, conn, tmp, module_name, module_args, inject):
|
||||||
executable = None
|
executable = None
|
||||||
args = []
|
args = []
|
||||||
for arg in module_args.split(' '):
|
for arg in shlex.split(module_args.encode("utf-8")):
|
||||||
if arg.startswith('executable='):
|
if arg.startswith('executable='):
|
||||||
executable = '='.join(arg.split('=')[1:])
|
executable = arg.split('=', 1)[1]
|
||||||
else:
|
else:
|
||||||
args.append(arg)
|
args.append(arg)
|
||||||
module_args = ' '.join(args).encode('utf-8')
|
module_args = ' '.join(args)
|
||||||
|
|
||||||
return ReturnData(conn=conn,
|
return ReturnData(conn=conn,
|
||||||
result=self.runner._low_level_exec_command(conn, module_args, tmp, sudoable=True, executable=executable)
|
result=self.runner._low_level_exec_command(conn, module_args, tmp, sudoable=True, executable=executable)
|
||||||
|
|
|
@ -110,7 +110,10 @@ class Connection(object):
|
||||||
chan.get_pty()
|
chan.get_pty()
|
||||||
|
|
||||||
if not self.runner.sudo or not sudoable:
|
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)
|
vvv("EXEC %s" % quoted_command, host=self.host)
|
||||||
chan.exec_command(quoted_command)
|
chan.exec_command(quoted_command)
|
||||||
else:
|
else:
|
||||||
|
@ -123,8 +126,12 @@ class Connection(object):
|
||||||
# the -p option.
|
# the -p option.
|
||||||
randbits = ''.join(chr(random.randint(ord('a'), ord('z'))) for x in xrange(32))
|
randbits = ''.join(chr(random.randint(ord('a'), ord('z'))) for x in xrange(32))
|
||||||
prompt = '[sudo via ansible, key=%s] password: ' % randbits
|
prompt = '[sudo via ansible, key=%s] password: ' % randbits
|
||||||
sudocmd = 'sudo -k && sudo -p "%s" -u %s %s -c %s' % (
|
sudocmd = 'sudo -k && sudo -p "%s" -u %s ' % (
|
||||||
prompt, sudo_user, executable, pipes.quote(cmd))
|
prompt, sudo_user)
|
||||||
|
if executable:
|
||||||
|
sudocmd += "%s -c %s" % (executable, pipes.quote(cmd))
|
||||||
|
else:
|
||||||
|
sudocmd += cmd
|
||||||
shcmd = '/bin/sh -c ' + pipes.quote(sudocmd)
|
shcmd = '/bin/sh -c ' + pipes.quote(sudocmd)
|
||||||
vvv("EXEC %s" % shcmd, host=self.host)
|
vvv("EXEC %s" % shcmd, host=self.host)
|
||||||
sudo_output = ''
|
sudo_output = ''
|
||||||
|
|
|
@ -88,7 +88,10 @@ class Connection(object):
|
||||||
ssh_cmd += ["ssh", "-tt", "-q"] + self.common_args + [self.host]
|
ssh_cmd += ["ssh", "-tt", "-q"] + self.common_args + [self.host]
|
||||||
|
|
||||||
if not self.runner.sudo or not sudoable:
|
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:
|
else:
|
||||||
# Rather than detect if sudo wants a password this time, -k makes
|
# Rather than detect if sudo wants a password this time, -k makes
|
||||||
# sudo always ask for a password if one is required.
|
# sudo always ask for a password if one is required.
|
||||||
|
@ -99,8 +102,12 @@ class Connection(object):
|
||||||
# the -p option.
|
# the -p option.
|
||||||
randbits = ''.join(chr(random.randint(ord('a'), ord('z'))) for x in xrange(32))
|
randbits = ''.join(chr(random.randint(ord('a'), ord('z'))) for x in xrange(32))
|
||||||
prompt = '[sudo via ansible, key=%s] password: ' % randbits
|
prompt = '[sudo via ansible, key=%s] password: ' % randbits
|
||||||
sudocmd = 'sudo -k && sudo -p "%s" -u %s %s -c %s' % (
|
sudocmd = 'sudo -k && sudo -p "%s" -u %s ' % (
|
||||||
prompt, sudo_user, executable, pipes.quote(cmd))
|
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))
|
ssh_cmd.append('/bin/sh -c ' + pipes.quote(sudocmd))
|
||||||
|
|
||||||
vvv("EXEC %s" % ssh_cmd, host=self.host)
|
vvv("EXEC %s" % ssh_cmd, host=self.host)
|
||||||
|
|
Loading…
Reference in a new issue