1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Support remote_user in jail connection plugin.

Resolves #6072.
This commit is contained in:
Matt Clay 2016-03-25 16:55:03 -07:00
parent fac3bac72e
commit b60062bdf9

View file

@ -94,7 +94,7 @@ class Connection(ConnectionBase):
''' connect to the jail; nothing to do here ''' ''' connect to the jail; nothing to do here '''
super(Connection, self)._connect() super(Connection, self)._connect()
if not self._connected: if not self._connected:
display.vvv("THIS IS A LOCAL JAIL DIR", host=self.jail) display.vvv(u"ESTABLISH JAIL CONNECTION FOR USER: {0}".format(self._play_context.remote_user), host=self.jail)
self._connected = True self._connected = True
def _buffered_exec_command(self, cmd, stdin=subprocess.PIPE): def _buffered_exec_command(self, cmd, stdin=subprocess.PIPE):
@ -105,8 +105,16 @@ class Connection(ConnectionBase):
compared to exec_command() it looses some niceties like being able to compared to exec_command() it looses some niceties like being able to
return the process's exit code immediately. return the process's exit code immediately.
''' '''
executable = C.DEFAULT_EXECUTABLE.split()[0] if C.DEFAULT_EXECUTABLE else '/bin/sh'
local_cmd = [self.jexec_cmd, self.jail, executable, '-c', cmd] local_cmd = [self.jexec_cmd]
set_env = ''
if self._play_context.remote_user is not None:
local_cmd += ['-U', self._play_context.remote_user]
# update HOME since -U does not update the jail environment
set_env = 'HOME=~' + self._play_context.remote_user + ' '
local_cmd += [self.jail, self._play_context.executable, '-c', set_env + cmd]
display.vvv("EXEC %s" % (local_cmd,), host=self.jail) display.vvv("EXEC %s" % (local_cmd,), host=self.jail)
local_cmd = [to_bytes(i, errors='strict') for i in local_cmd] local_cmd = [to_bytes(i, errors='strict') for i in local_cmd]