1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

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 <felix@fontein.de>

* Create 80-update_docker_connection_plugin.yml

Add changelog fragment

* Update changelogs/fragments/80-update_docker_connection_plugin.yml

Co-Authored-By: Felix Fontein <felix@fontein.de>

Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
Ruheena Ansari 2020-03-31 14:42:16 -04:00 committed by GitHub
parent 0205adef24
commit 07e8911fd8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 4 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- docker connection plugin - do not prefix remote path if running on Windows containers.

View file

@ -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`