Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PR #243/bed775c4 backport][stable-1] docker_container_exec: improve handling of chdir option #247

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelogs/fragments/243-docker_container_exec-chdir.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
bugfixes:
- "docker_container_exec - ``chdir`` is only supported since Docker SDK for Python 3.0.0. Make sure that this option can only use when 3.0.0 or later is installed, and prevent passing this parameter on when ``chdir`` is not provided to this module (https://github.com/ansible-collections/community.docker/pull/243, https://github.com/ansible-collections/community.docker/issues/242)."
- "docker_api connection plugin - avoid passing an unnecessary argument to a Docker SDK for Python call that is only supported by version 3.0.0 or later (https://github.com/ansible-collections/community.docker/pull/243)."
2 changes: 1 addition & 1 deletion plugins/connection/docker_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def exec_command(self, cmd, in_data=None, sudoable=False):
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']

Expand Down
10 changes: 9 additions & 1 deletion plugins/modules/docker_container_exec.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')],
Expand All @@ -190,14 +195,17 @@ def main():
selectors = find_selectors(client.module)

try:
kwargs = {}
if chdir is not None:
kwargs['workdir'] = chdir
exec_data = client.exec_create(
container,
argv,
stdout=True,
stderr=True,
stdin=bool(stdin),
user=user or '',
workdir=chdir,
**kwargs
)
exec_id = exec_data['Id']

Expand Down