summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Coca <bcoca@ansible.com>2016-03-28 09:22:00 -0700
committerBrian Coca <bcoca@ansible.com>2016-03-28 09:22:00 -0700
commit04610106a322f0a08bb05f2234c016975b970b74 (patch)
tree94a048b004a0a120900f2ad37fc9f093f05ebc88
parente9a4526251d24370ffcd1761cb62460c4f548676 (diff)
parentb60062bdf9af6439e18b58c8c39f40c81d1c52a7 (diff)
downloadansible-04610106a322f0a08bb05f2234c016975b970b74.tar.gz
Merge pull request #15173 from mattclay/issue6072
Support remote_user in jail connection plugin.
-rw-r--r--lib/ansible/plugins/connection/jail.py14
1 files 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]