docker_swarm inventory plugin: New group non-leader (#54266)

* New group `non-leader` to contain all nodes (workers and managers) except the swarm leader

* New group name change, documentation section updates

* New group name change, documentation section more updates
This commit is contained in:
Piotr Wojciechowski 2019-03-24 14:57:16 +01:00 committed by ansibot
parent 752db43b2d
commit 0ec2d71b4a

View file

@ -22,9 +22,13 @@ DOCUMENTATION = '''
description: description:
- Reads inventories from the Docker swarm API. - Reads inventories from the Docker swarm API.
- Uses a YAML configuration file docker_swarm.[yml|yaml]. - Uses a YAML configuration file docker_swarm.[yml|yaml].
- "The plugin returns following groups of swarm nodes: I(all) - all hosts; I(workers) - all worker nodes;
I(managers) - all manager nodes; I(leader) - the swarm leader node;
I(nonleaders) - all nodes except the swarm leader."
options: options:
plugin: plugin:
description: The name of this plugin, it should always be set to C(docker_swarm) for this plugin to recognize it as it's own. description: The name of this plugin, it should always be set to C(docker_swarm) for this plugin to
recognize it as it's own.
type: str type: str
required: true required: true
choices: docker_swarm choices: docker_swarm
@ -35,7 +39,8 @@ DOCUMENTATION = '''
type: str type: str
required: true required: true
verbose_output: verbose_output:
description: Toggle to (not) include all available nodes metadata (e.g. Platform, Architecture, OS, EngineVersion) description: Toggle to (not) include all available nodes metadata (e.g. Platform, Architecture,OS,
EngineVersion)
type: bool type: bool
default: yes default: yes
tls: tls:
@ -43,20 +48,23 @@ DOCUMENTATION = '''
type: bool type: bool
default: no default: no
tls_verify: tls_verify:
description: Toggle if connecting using TLS with or without verifying the authenticity of the Docker host server. description: Toggle if connecting using TLS with or without verifying the authenticity of the Docker
host server.
type: bool type: bool
default: no default: no
key_path: key_path:
description: Path to the client's TLS key file. description: Path to the client's TLS key file.
type: path type: path
cacert_path: cacert_path:
description: Use a CA certificate when performing server verification by providing the path to a CA certificate file. description: Use a CA certificate when performing server verification by providing the path to a CA
certificate file.
type: path type: path
cert_path: cert_path:
description: Path to the client's TLS certificate file. description: Path to the client's TLS certificate file.
type: path type: path
tls_hostname: tls_hostname:
description: When verifying the authenticity of the Docker host server, provide the expected name of the server. description: When verifying the authenticity of the Docker host server, provide the expected name of
the server.
type: str type: str
ssl_version: ssl_version:
description: Provide a valid SSL version number. Default value determined by ssl.py module. description: Provide a valid SSL version number. Default value determined by ssl.py module.
@ -69,8 +77,8 @@ DOCUMENTATION = '''
timeout: timeout:
description: description:
- The maximum amount of time in seconds to wait on a response from the API. - The maximum amount of time in seconds to wait on a response from the API.
- If the value is not specified in the task, the value of environment variable C(DOCKER_TIMEOUT) will be used - If the value is not specified in the task, the value of environment variable C(DOCKER_TIMEOUT)
instead. If the environment variable is not set, the default value will be used. will be used instead. If the environment variable is not set, the default value will be used.
type: int type: int
default: 60 default: 60
include_host_uri: include_host_uri:
@ -172,6 +180,7 @@ class InventoryModule(BaseInventoryPlugin, Constructable):
self.inventory.add_group('manager') self.inventory.add_group('manager')
self.inventory.add_group('worker') self.inventory.add_group('worker')
self.inventory.add_group('leader') self.inventory.add_group('leader')
self.inventory.add_group('nonleaders')
if self.get_option('include_host_uri', True): if self.get_option('include_host_uri', True):
if self.get_option('include_host_uri_port'): if self.get_option('include_host_uri_port'):
@ -205,6 +214,10 @@ class InventoryModule(BaseInventoryPlugin, Constructable):
swarm_leader_ip + ":" + host_uri_port) swarm_leader_ip + ":" + host_uri_port)
self.inventory.set_variable(self.node_attrs['ID'], 'ansible_host', swarm_leader_ip) self.inventory.set_variable(self.node_attrs['ID'], 'ansible_host', swarm_leader_ip)
self.inventory.add_host(self.node_attrs['ID'], group='leader') self.inventory.add_host(self.node_attrs['ID'], group='leader')
else:
self.inventory.add_host(self.node_attrs['ID'], group='nonleaders')
else:
self.inventory.add_host(self.node_attrs['ID'], group='nonleaders')
# Use constructed if applicable # Use constructed if applicable
strict = self.get_option('strict') strict = self.get_option('strict')
# Composed variables # Composed variables