use remote_user or become_user in docker connection

pull/13227/merge
Thomas Steinbach 9 years ago committed by Toshio Kuratomi
parent 5d9b552317
commit 4ac49ed4a8

@ -121,8 +121,9 @@ class Connection(ConnectionBase):
super(Connection, self).exec_command(cmd, in_data=in_data, sudoable=sudoable) 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' 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 # -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) display.vvv("EXEC %s" % (local_cmd,), host=self._play_context.remote_addr)
local_cmd = [to_bytes(i, errors='strict') for i in local_cmd] 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 # Older docker doesn't have native support for copying files into
# running containers, so we use docker exec to implement this # running containers, so we use docker exec to implement this
executable = C.DEFAULT_EXECUTABLE.split()[0] if C.DEFAULT_EXECUTABLE else '/bin/sh' 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)] "dd of=%s bs=%s" % (out_path, BUFSIZE)]
args = [to_bytes(i, errors='strict') for i in args] args = [to_bytes(i, errors='strict') for i in args]
with open(to_bytes(in_path, errors='strict'), 'rb') as in_file: with open(to_bytes(in_path, errors='strict'), 'rb') as in_file:

Loading…
Cancel
Save