mirror of
https://github.com/ansible-collections/community.docker.git
synced 2026-07-29 11:55:04 +00:00
docker_container_exec: improve handling of chdir option (#243)
* Only pass chdir on when it is provided, and prevent this option from being used for Docker SDK for Python < 3.0.0. * Also fix docker_api connection plugin.
This commit is contained in:
@@ -164,7 +164,7 @@ class Connection(ConnectionBase):
|
||||
stderr=True,
|
||||
stdin=need_stdin,
|
||||
user=self._play_context.remote_user or '',
|
||||
workdir=None,
|
||||
# workdir=None, - only works for Docker SDK for Python 3.0.0 and later
|
||||
))
|
||||
exec_id = exec_data['Id']
|
||||
|
||||
|
||||
@@ -163,8 +163,13 @@ def main():
|
||||
tty=dict(type='bool', default=False),
|
||||
)
|
||||
|
||||
option_minimal_versions = dict(
|
||||
chdir=dict(docker_py_version='3.0.0'),
|
||||
)
|
||||
|
||||
client = AnsibleDockerClient(
|
||||
argument_spec=argument_spec,
|
||||
option_minimal_versions=option_minimal_versions,
|
||||
min_docker_api_version='1.20',
|
||||
mutually_exclusive=[('argv', 'command')],
|
||||
required_one_of=[('argv', 'command')],
|
||||
@@ -190,6 +195,9 @@ def main():
|
||||
selectors = find_selectors(client.module)
|
||||
|
||||
try:
|
||||
kwargs = {}
|
||||
if chdir is not None:
|
||||
kwargs['workdir'] = chdir
|
||||
exec_data = client.exec_create(
|
||||
container,
|
||||
argv,
|
||||
@@ -197,7 +205,7 @@ def main():
|
||||
stderr=True,
|
||||
stdin=bool(stdin),
|
||||
user=user or '',
|
||||
workdir=chdir,
|
||||
**kwargs
|
||||
)
|
||||
exec_id = exec_data['Id']
|
||||
|
||||
|
||||
Reference in New Issue
Block a user