From c6912647273e43a13a3dee1f6c68f2f49c1eafbc Mon Sep 17 00:00:00 2001 From: Ruheena Ansari Date: Tue, 31 Mar 2020 14:42:16 -0400 Subject: [PATCH] Update docker connection plugin (#80) * Update docker.py #67832 fixes the need to run powershell modules on windows containers via docker connection. However, while running win_copy on windows containers, destination path is prefixed, which doesn't work in the case of windows. The changes in this PR take care of bypassing that while running the ansible role on windows containers. * Update plugins/connection/docker.py Co-Authored-By: Felix Fontein * Create 80-update_docker_connection_plugin.yml Add changelog fragment * Update changelogs/fragments/80-update_docker_connection_plugin.yml Co-Authored-By: Felix Fontein Co-authored-by: Felix Fontein --- plugins/connection/docker.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/plugins/connection/docker.py b/plugins/connection/docker.py index 4ea197d4..74a74403 100644 --- a/plugins/connection/docker.py +++ b/plugins/connection/docker.py @@ -274,9 +274,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 """ @@ -328,7 +332,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`