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

docker_swarm: adds data_path_addr option for swarm init and swarm join #344

Merged
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
2 changes: 2 additions & 0 deletions changelogs/fragments/344-adds-data-path-addr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- docker_swarm - adds ``data_path_addr`` parameter during swarm initialization or when joining (https://github.com/ansible-collections/community.docker/issues/339).
24 changes: 22 additions & 2 deletions plugins/modules/docker_swarm.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,15 @@
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 is not
considered for idempotency checking.
type: str
chrische marked this conversation as resolved.
Show resolved Hide resolved
version_added: 2.5.0
extends_documentation_fragment:
- community.docker.docker
- community.docker.docker.docker_py_1_documentation
Expand Down Expand Up @@ -218,6 +227,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 +308,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 +414,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 +503,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 +565,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 +615,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 +661,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.30'),
)

client = AnsibleDockerSwarmClient(
Expand Down