From cc8d4bb4510bcc79537ed3fa591fb9cace576ae9 Mon Sep 17 00:00:00 2001 From: Abhijeet Kasurde Date: Sun, 10 May 2020 08:42:49 +0530 Subject: [PATCH] Add user flags before container id in podman exec (#19) * Add user flags before container id in podman exec When user provides an ansible_ssh_user, podman connection plugin includes this values as `--user` flag. This patch fixes the location of this flag according to podman exec command help. Fixes: ansible/ansible#65220 Signed-off-by: Abhijeet Kasurde * Don't use mount in case of specified user Co-authored-by: Sagi Shnaidman --- plugins/connection/podman.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/plugins/connection/podman.py b/plugins/connection/podman.py index 1ea1f94..6eea59f 100644 --- a/plugins/connection/podman.py +++ b/plugins/connection/podman.py @@ -109,7 +109,11 @@ class Connection(ConnectionBase): to_native( self.get_option('podman_extra_args'), errors='surrogate_or_strict')) - local_cmd.append(cmd) + if isinstance(cmd, str): + local_cmd.append(cmd) + else: + local_cmd.extend(cmd) + if use_container_id: local_cmd.append(self._container_id) if cmd_args: @@ -149,10 +153,11 @@ class Connection(ConnectionBase): # shlex.split has a bug with text strings on Python-2.6 and can only handle text strings on Python-3 cmd_args_list = shlex.split(to_native(cmd, errors='surrogate_or_strict')) + exec_args_list = ["exec"] if self.user: - cmd_args_list += ["--user", self.user] + exec_args_list.extend(("--user", self.user)) - rc, stdout, stderr = self._podman("exec", cmd_args_list, in_data) + rc, stdout, stderr = self._podman(exec_args_list, cmd_args_list, in_data) display.vvvvv("STDOUT %r STDERR %r" % (stderr, stderr)) return rc, stdout, stderr @@ -161,7 +166,7 @@ class Connection(ConnectionBase): """ Place a local file located in 'in_path' inside container at 'out_path' """ super(Connection, self).put_file(in_path, out_path) display.vvv("PUT %s TO %s" % (in_path, out_path), host=self._container_id) - if not self._mount_point: + if not self._mount_point or self.user: rc, stdout, stderr = self._podman( "cp", [in_path, self._container_id + ":" + out_path], use_container_id=False )