From 4ac49ed4a8535c4b4e1aab75bc0d7787be5907dd Mon Sep 17 00:00:00 2001 From: Thomas Steinbach Date: Fri, 4 Dec 2015 02:33:08 +0100 Subject: use remote_user or become_user in docker connection --- lib/ansible/plugins/connection/docker.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'lib/ansible/plugins/connection/docker.py') diff --git a/lib/ansible/plugins/connection/docker.py b/lib/ansible/plugins/connection/docker.py index 13c6d8dc90..999b94c22d 100644 --- a/lib/ansible/plugins/connection/docker.py +++ b/lib/ansible/plugins/connection/docker.py @@ -121,8 +121,9 @@ class Connection(ConnectionBase): super(Connection, self).exec_command(cmd, in_data=in_data, sudoable=sudoable) executable = C.DEFAULT_EXECUTABLE.split()[0] if C.DEFAULT_EXECUTABLE else '/bin/sh' + exec_user = self._play_context.become_user if self._play_context.become else self._play_context.remote_user # -i is needed to keep stdin open which allows pipelining to work - local_cmd = [self.docker_cmd, "exec", '-i', self._play_context.remote_addr, executable, '-c', cmd] + local_cmd = [self.docker_cmd, "exec", '-u', exec_user, '-i', self._play_context.remote_addr, executable, '-c', cmd] display.vvv("EXEC %s" % (local_cmd,), host=self._play_context.remote_addr) local_cmd = [to_bytes(i, errors='strict') for i in local_cmd] @@ -169,7 +170,8 @@ class Connection(ConnectionBase): # Older docker doesn't have native support for copying files into # running containers, so we use docker exec to implement this executable = C.DEFAULT_EXECUTABLE.split()[0] if C.DEFAULT_EXECUTABLE else '/bin/sh' - args = [self.docker_cmd, "exec", "-i", self._play_context.remote_addr, executable, "-c", + exec_user = self._play_context.become_user if self._play_context.become else self._play_context.remote_user + args = [self.docker_cmd, "exec", "-u", exec_user, "-i", self._play_context.remote_addr, executable, "-c", "dd of=%s bs=%s" % (out_path, BUFSIZE)] args = [to_bytes(i, errors='strict') for i in args] with open(to_bytes(in_path, errors='strict'), 'rb') as in_file: -- cgit v1.2.1