From 2b536b8e822a353ce2db495c118cb2d8f6a777c0 Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Tue, 31 Mar 2020 21:23:01 +0200 Subject: [PATCH] Backport of ansible-collections/community.general@07e8911fd8b1415fb1cbb760c7291079e756da59 to stable-2.9. --- ...eneral-80-update_docker_connection_plugin.yml | 2 ++ lib/ansible/plugins/connection/docker.py | 16 ++++++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) create mode 100644 changelogs/fragments/community.general-80-update_docker_connection_plugin.yml diff --git a/changelogs/fragments/community.general-80-update_docker_connection_plugin.yml b/changelogs/fragments/community.general-80-update_docker_connection_plugin.yml new file mode 100644 index 00000000000..dfc2b7116c9 --- /dev/null +++ b/changelogs/fragments/community.general-80-update_docker_connection_plugin.yml @@ -0,0 +1,2 @@ +bugfixes: + - docker connection plugin - do not prefix remote path if running on Windows containers. diff --git a/lib/ansible/plugins/connection/docker.py b/lib/ansible/plugins/connection/docker.py index 380a84d877d..a32ac37bb57 100644 --- a/lib/ansible/plugins/connection/docker.py +++ b/lib/ansible/plugins/connection/docker.py @@ -275,9 +275,13 @@ class Connection(ConnectionBase): Can revisit using $HOME instead if it's a problem ''' - if not remote_path.startswith(os.path.sep): - remote_path = os.path.join(os.path.sep, remote_path) - return os.path.normpath(remote_path) + if getattr(self._shell, "_IS_WINDOWS", False): + import ntpath + return ntpath.normpath(remote_path) + else: + if not remote_path.startswith(os.path.sep): + remote_path = os.path.join(os.path.sep, remote_path) + return os.path.normpath(remote_path) def put_file(self, in_path, out_path): """ Transfer a file from local to docker container """ @@ -329,7 +333,11 @@ class Connection(ConnectionBase): stdout=subprocess.PIPE, stderr=subprocess.PIPE) p.communicate() - actual_out_path = os.path.join(out_dir, os.path.basename(in_path)) + if getattr(self._shell, "_IS_WINDOWS", False): + import ntpath + actual_out_path = ntpath.join(out_dir, ntpath.basename(in_path)) + else: + actual_out_path = os.path.join(out_dir, os.path.basename(in_path)) if p.returncode != 0: # Older docker doesn't have native support for fetching files command `cp`