Skip to content

Commit

Permalink
adds data_path_addr option for swarm init and swarm join. (ansible-co…
Browse files Browse the repository at this point in the history
  • Loading branch information
chrische committed May 2, 2022
1 parent 51d4c55 commit e7a9959
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions plugins/modules/docker_swarm.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,14 @@
description: Rotate the manager join token.
type: bool
default: no
data_path_addr:
description:
- Address or interface to use for data path traffic.
- This can either be an address in the form C(192.168.1.1), or an interface,
like C(eth0).
- Only used when swarm is initialised or joined. Because of this it's not
considered for idempotency checking.
type: str
extends_documentation_fragment:
- community.docker.docker
- community.docker.docker.docker_py_1_documentation
Expand Down Expand Up @@ -218,6 +226,12 @@
community.docker.docker_swarm:
state: remove
node_id: mynode
- name: Init a new swarm with different data path interface
community.docker.docker_swarm:
state: present
advertise_addr: eth0
data_path_addr: ens10
'''

RETURN = '''
Expand Down Expand Up @@ -293,6 +307,7 @@ def __init__(self):
self.listen_addr = None
self.remote_addrs = None
self.join_token = None
self.data_path_addr = None

# Spec
self.snapshot_interval = None
Expand Down Expand Up @@ -398,7 +413,7 @@ def compare_to_active(self, other, client, differences):
for k in self.__dict__:
if k in ('advertise_addr', 'listen_addr', 'remote_addrs', 'join_token',
'rotate_worker_token', 'rotate_manager_token', 'spec',
'default_addr_pool', 'subnet_size'):
'default_addr_pool', 'subnet_size', 'data_path_addr'):
continue
if not client.option_minimal_versions[k]['supported']:
continue
Expand Down Expand Up @@ -487,6 +502,7 @@ def init_swarm(self):
init_arguments = {
'advertise_addr': self.parameters.advertise_addr,
'listen_addr': self.parameters.listen_addr,
'data_path_addr': self.parameters.data_path_addr,
'force_new_cluster': self.force,
'swarm_spec': self.parameters.spec,
}
Expand Down Expand Up @@ -548,7 +564,8 @@ def join(self):
try:
self.client.join_swarm(
remote_addrs=self.parameters.remote_addrs, join_token=self.parameters.join_token,
listen_addr=self.parameters.listen_addr, advertise_addr=self.parameters.advertise_addr)
listen_addr=self.parameters.listen_addr, advertise_addr=self.parameters.advertise_addr,
data_path_addr=self.parameters.data_path_addr)
except APIError as exc:
self.client.fail("Can not join the Swarm Cluster: %s" % to_native(exc))
self.results['actions'].append("New node is added to swarm cluster")
Expand Down Expand Up @@ -597,6 +614,7 @@ def _detect_remove_operation(client):
def main():
argument_spec = dict(
advertise_addr=dict(type='str'),
data_path_addr=dict(type='str'),
state=dict(type='str', default='present', choices=['present', 'join', 'absent', 'remove']),
force=dict(type='bool', default=False),
listen_addr=dict(type='str', default='0.0.0.0:2377'),
Expand Down Expand Up @@ -642,6 +660,7 @@ def main():
),
default_addr_pool=dict(docker_py_version='4.0.0', docker_api_version='1.39'),
subnet_size=dict(docker_py_version='4.0.0', docker_api_version='1.39'),
data_path_addr=dict(docker_py_version='4.0.0', docker_api_version='1.31'),
)

client = AnsibleDockerSwarmClient(
Expand Down

0 comments on commit e7a9959

Please sign in to comment.