Skip to content

Commit

Permalink
Make docker_host and cli_context mutually exclusive. (ansible-collect…
Browse files Browse the repository at this point in the history
  • Loading branch information
felixfontein authored and AndrewJDawes committed Jun 29, 2024
1 parent d393566 commit 2ec7b35
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/895-docker-cli.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- "docker_compose_v2*, docker_stack*, docker_image_build modules - using ``cli_context`` no longer leads to an invalid parameter combination being passed to the corresponding Docker CLI tool, unless ``docker_host`` is also provided. Combining ``cli_context`` and ``docker_host`` is no longer allowed (https://github.com/ansible-collections/community.docker/issues/892, https://github.com/ansible-collections/community.docker/pull/895)."
4 changes: 3 additions & 1 deletion plugins/doc_fragments/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,9 @@ class ModuleDocFragment(object):
the module will automatically replace C(tcp) in the connection URL with C(https).
- If the value is not specified in the task, the value of environment variable E(DOCKER_HOST) will be used
instead. If the environment variable is not set, the default value will be used.
- Mutually exclusive with O(cli_context). If neither O(docker_host) nor O(cli_context) are provided, the
value V(unix:///var/run/docker.sock) is used.
type: str
default: unix:///var/run/docker.sock
aliases: [ docker_url ]
tls_hostname:
description:
Expand Down Expand Up @@ -381,6 +382,7 @@ class ModuleDocFragment(object):
cli_context:
description:
- The Docker CLI context to use.
- Mutually exclusive with O(docker_host).
type: str
notes:
Expand Down
10 changes: 7 additions & 3 deletions plugins/module_utils/common_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

DOCKER_COMMON_ARGS = dict(
docker_cli=dict(type='path'),
docker_host=dict(type='str', default=DEFAULT_DOCKER_HOST, fallback=(env_fallback, ['DOCKER_HOST']), aliases=['docker_url']),
docker_host=dict(type='str', fallback=(env_fallback, ['DOCKER_HOST']), aliases=['docker_url']),
tls_hostname=dict(type='str', fallback=(env_fallback, ['DOCKER_TLS_HOSTNAME'])),
api_version=dict(type='str', default='auto', fallback=(env_fallback, ['DOCKER_API_VERSION']), aliases=['docker_api_version']),
ca_path=dict(type='path', aliases=['ca_cert', 'tls_ca_cert', 'cacert_path']),
Expand Down Expand Up @@ -62,7 +62,11 @@ def __init__(self, common_args, min_docker_api_version=None):
self.fail('Cannot find docker CLI in path. Please provide it explicitly with the docker_cli parameter')

self._cli_base = [self._cli]
self._cli_base.extend(['--host', common_args['docker_host']])
docker_host = common_args['docker_host']
if not docker_host and not common_args['cli_context']:
docker_host = DEFAULT_DOCKER_HOST
if docker_host:
self._cli_base.extend(['--host', docker_host])
if common_args['validate_certs']:
self._cli_base.append('--tlsverify')
elif common_args['tls']:
Expand Down Expand Up @@ -275,7 +279,7 @@ def __init__(self, argument_spec=None, supports_check_mode=False, mutually_exclu
merged_arg_spec.update(argument_spec)
self.arg_spec = merged_arg_spec

mutually_exclusive_params = []
mutually_exclusive_params = [('docker_host', 'cli_context')]
mutually_exclusive_params += DOCKER_MUTUALLY_EXCLUSIVE
if mutually_exclusive:
mutually_exclusive_params += mutually_exclusive
Expand Down

0 comments on commit 2ec7b35

Please sign in to comment.