mirror of
https://github.com/ansible-collections/community.docker.git
synced 2026-03-15 19:58:28 +00:00
Pass Docker daemon connection params from inventory to connection plugin (#157)
* Move variable handling to doc fragment, and make them known to module_utils. * Pass Daemon connection options to connection plugin. * Add changelog fragment. * Fix syntax error. * Forgot 'options:'.
This commit is contained in:
parent
d0d5bdb905
commit
902bcc6193
@ -0,0 +1,2 @@
|
|||||||
|
minor_changes:
|
||||||
|
- "docker_containers inventory plugin - when ``connection_type=docker-api``, now pass Docker daemon connection options from inventory plugin to connection plugin. This can be disabled by setting ``configure_docker_daemon=false`` (https://github.com/ansible-collections/community.docker/pull/157)."
|
||||||
@ -33,41 +33,9 @@ options:
|
|||||||
- name: ansible_host
|
- name: ansible_host
|
||||||
- name: ansible_docker_host
|
- name: ansible_docker_host
|
||||||
|
|
||||||
# The following are options from the docs fragment. We want to allow the user to
|
|
||||||
# specify them with Ansible variables.
|
|
||||||
docker_host:
|
|
||||||
vars:
|
|
||||||
- name: ansible_docker_docker_host
|
|
||||||
tls_hostname:
|
|
||||||
vars:
|
|
||||||
- name: ansible_docker_tls_hostname
|
|
||||||
api_version:
|
|
||||||
vars:
|
|
||||||
- name: ansible_docker_api_version
|
|
||||||
timeout:
|
|
||||||
vars:
|
|
||||||
- name: ansible_docker_timeout
|
|
||||||
ca_cert:
|
|
||||||
vars:
|
|
||||||
- name: ansible_docker_ca_cert
|
|
||||||
client_cert:
|
|
||||||
vars:
|
|
||||||
- name: ansible_docker_client_cert
|
|
||||||
client_key:
|
|
||||||
vars:
|
|
||||||
- name: ansible_docker_client_key
|
|
||||||
ssl_version:
|
|
||||||
vars:
|
|
||||||
- name: ansible_docker_ssl_version
|
|
||||||
tls:
|
|
||||||
vars:
|
|
||||||
- name: ansible_docker_tls
|
|
||||||
validate_certs:
|
|
||||||
vars:
|
|
||||||
- name: ansible_docker_validate_certs
|
|
||||||
|
|
||||||
extends_documentation_fragment:
|
extends_documentation_fragment:
|
||||||
- community.docker.docker
|
- community.docker.docker
|
||||||
|
- community.docker.docker.var_names
|
||||||
- community.docker.docker.docker_py_1_documentation
|
- community.docker.docker.docker_py_1_documentation
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
|||||||
@ -116,6 +116,42 @@ notes:
|
|||||||
and use C($DOCKER_CONFIG/config.json) otherwise.
|
and use C($DOCKER_CONFIG/config.json) otherwise.
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
# For plugins: allow to define common options with Ansible variables
|
||||||
|
|
||||||
|
VAR_NAMES = r'''
|
||||||
|
options:
|
||||||
|
docker_host:
|
||||||
|
vars:
|
||||||
|
- name: ansible_docker_docker_host
|
||||||
|
tls_hostname:
|
||||||
|
vars:
|
||||||
|
- name: ansible_docker_tls_hostname
|
||||||
|
api_version:
|
||||||
|
vars:
|
||||||
|
- name: ansible_docker_api_version
|
||||||
|
timeout:
|
||||||
|
vars:
|
||||||
|
- name: ansible_docker_timeout
|
||||||
|
ca_cert:
|
||||||
|
vars:
|
||||||
|
- name: ansible_docker_ca_cert
|
||||||
|
client_cert:
|
||||||
|
vars:
|
||||||
|
- name: ansible_docker_client_cert
|
||||||
|
client_key:
|
||||||
|
vars:
|
||||||
|
- name: ansible_docker_client_key
|
||||||
|
ssl_version:
|
||||||
|
vars:
|
||||||
|
- name: ansible_docker_ssl_version
|
||||||
|
tls:
|
||||||
|
vars:
|
||||||
|
- name: ansible_docker_tls
|
||||||
|
validate_certs:
|
||||||
|
vars:
|
||||||
|
- name: ansible_docker_validate_certs
|
||||||
|
'''
|
||||||
|
|
||||||
# Additional, more specific stuff for minimal Docker SDK for Python version < 2.0
|
# Additional, more specific stuff for minimal Docker SDK for Python version < 2.0
|
||||||
|
|
||||||
DOCKER_PY_1_DOCUMENTATION = r'''
|
DOCKER_PY_1_DOCUMENTATION = r'''
|
||||||
|
|||||||
@ -44,6 +44,8 @@ options:
|
|||||||
R(docker connection plugin,ansible_collections.community.docker.docker_connection),
|
R(docker connection plugin,ansible_collections.community.docker.docker_connection),
|
||||||
and C(docker-api) selects the
|
and C(docker-api) selects the
|
||||||
R(docker_api connection plugin,ansible_collections.community.docker.docker_api_connection).
|
R(docker_api connection plugin,ansible_collections.community.docker.docker_api_connection).
|
||||||
|
- When C(docker-api) is used, all Docker daemon configuration values are passed from the inventory plugin
|
||||||
|
to the connection plugin. This can be controlled with I(configure_docker_daemon).
|
||||||
type: str
|
type: str
|
||||||
default: docker-api
|
default: docker-api
|
||||||
choices:
|
choices:
|
||||||
@ -51,6 +53,14 @@ options:
|
|||||||
- docker-cli
|
- docker-cli
|
||||||
- docker-api
|
- docker-api
|
||||||
|
|
||||||
|
configure_docker_daemon:
|
||||||
|
description:
|
||||||
|
- Whether to pass all Docker daemon configuration from the inventory plugin to the connection plugin.
|
||||||
|
- Only used when I(connection_type=docker-api).
|
||||||
|
type: bool
|
||||||
|
default: true
|
||||||
|
version_added: 1.8.0
|
||||||
|
|
||||||
verbose_output:
|
verbose_output:
|
||||||
description:
|
description:
|
||||||
- Toggle to (not) include all available inspection metadata.
|
- Toggle to (not) include all available inspection metadata.
|
||||||
@ -138,6 +148,7 @@ from ansible.plugins.inventory import BaseInventoryPlugin, Constructable
|
|||||||
|
|
||||||
from ansible_collections.community.docker.plugins.module_utils.common import (
|
from ansible_collections.community.docker.plugins.module_utils.common import (
|
||||||
RequestException,
|
RequestException,
|
||||||
|
DOCKER_COMMON_ARGS_VARS,
|
||||||
)
|
)
|
||||||
from ansible_collections.community.docker.plugins.plugin_utils.common import (
|
from ansible_collections.community.docker.plugins.plugin_utils.common import (
|
||||||
AnsibleDockerClient,
|
AnsibleDockerClient,
|
||||||
@ -180,6 +191,13 @@ class InventoryModule(BaseInventoryPlugin, Constructable):
|
|||||||
self.inventory.add_group('running')
|
self.inventory.add_group('running')
|
||||||
self.inventory.add_group('stopped')
|
self.inventory.add_group('stopped')
|
||||||
|
|
||||||
|
extra_facts = {}
|
||||||
|
if self.get_option('configure_docker_daemon'):
|
||||||
|
for option_name, var_name in DOCKER_COMMON_ARGS_VARS.items():
|
||||||
|
value = self.get_option(option_name)
|
||||||
|
if value is not None:
|
||||||
|
extra_facts[var_name] = value
|
||||||
|
|
||||||
for container in containers:
|
for container in containers:
|
||||||
id = container.get('Id')
|
id = container.get('Id')
|
||||||
short_id = id[:13]
|
short_id = id[:13]
|
||||||
@ -256,6 +274,7 @@ class InventoryModule(BaseInventoryPlugin, Constructable):
|
|||||||
ansible_host=full_name,
|
ansible_host=full_name,
|
||||||
ansible_connection='community.docker.docker_api',
|
ansible_connection='community.docker.docker_api',
|
||||||
))
|
))
|
||||||
|
facts.update(extra_facts)
|
||||||
|
|
||||||
full_facts.update(facts)
|
full_facts.update(facts)
|
||||||
for key, value in inspect.items():
|
for key, value in inspect.items():
|
||||||
|
|||||||
@ -96,6 +96,12 @@ DOCKER_COMMON_ARGS = dict(
|
|||||||
debug=dict(type='bool', default=False)
|
debug=dict(type='bool', default=False)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
DOCKER_COMMON_ARGS_VARS = dict([
|
||||||
|
[option_name, 'ansible_docker_%s' % option_name]
|
||||||
|
for option_name in DOCKER_COMMON_ARGS
|
||||||
|
if option_name != 'debug'
|
||||||
|
])
|
||||||
|
|
||||||
DOCKER_MUTUALLY_EXCLUSIVE = []
|
DOCKER_MUTUALLY_EXCLUSIVE = []
|
||||||
|
|
||||||
DOCKER_REQUIRED_TOGETHER = [
|
DOCKER_REQUIRED_TOGETHER = [
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user