From b60062bdf9af6439e18b58c8c39f40c81d1c52a7 Mon Sep 17 00:00:00 2001 From: Matt Clay Date: Fri, 25 Mar 2016 16:55:03 -0700 Subject: [PATCH] Support remote_user in jail connection plugin. Resolves #6072. --- lib/ansible/plugins/connection/jail.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/ansible/plugins/connection/jail.py b/lib/ansible/plugins/connection/jail.py index 844d94c51f..ac2cdf9891 100644 --- a/lib/ansible/plugins/connection/jail.py +++ b/lib/ansible/plugins/connection/jail.py @@ -94,7 +94,7 @@ class Connection(ConnectionBase): ''' connect to the jail; nothing to do here ''' super(Connection, self)._connect() 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 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 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) local_cmd = [to_bytes(i, errors='strict') for i in local_cmd]