Skip to content

Commit

Permalink
Do not pass data_path_addr for older Docker SDK for Python versions. (a…
Browse files Browse the repository at this point in the history
  • Loading branch information
felixfontein authored Oct 14, 2023
1 parent 33c0957 commit fbc2750
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
3 changes: 3 additions & 0 deletions changelogs/fragments/696-docker_swarm-data_addr_path.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
bugfixes:
- "docker_swarm - make init and join operations work again with Docker SDK for Python before 4.0.0
(https://github.com/ansible-collections/community.docker/issues/695, https://github.com/ansible-collections/community.docker/pull/696)."
18 changes: 13 additions & 5 deletions plugins/modules/docker_swarm.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@
like V(eth0).
- Only used when swarm is initialised or joined. Because of this it is not
considered for idempotency checking.
- Requires API version >= 1.30.
type: str
version_added: 2.5.0
data_path_port:
Expand All @@ -207,6 +208,7 @@
- This needs to be a port number like V(9789).
- Only used when swarm is initialised. Because of this it is not
considered for idempotency checking.
- Requires API version >= 1.40.
type: int
version_added: 3.1.0
Expand Down Expand Up @@ -534,14 +536,15 @@ 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,
}
if self.parameters.default_addr_pool is not None:
init_arguments['default_addr_pool'] = self.parameters.default_addr_pool
if self.parameters.subnet_size is not None:
init_arguments['subnet_size'] = self.parameters.subnet_size
if self.parameters.data_path_addr is not None:
init_arguments['data_path_addr'] = self.parameters.data_path_addr
if self.parameters.data_path_port is not None:
init_arguments['data_path_port'] = self.parameters.data_path_port
try:
Expand Down Expand Up @@ -595,11 +598,16 @@ def join(self):
self.results['actions'].append("This node is already part of a swarm.")
return
if not self.check_mode:
join_arguments = {
'remote_addrs': self.parameters.remote_addrs,
'join_token': self.parameters.join_token,
'listen_addr': self.parameters.listen_addr,
'advertise_addr': self.parameters.advertise_addr,
}
if self.parameters.data_path_addr is not None:
join_arguments['data_path_addr'] = self.parameters.data_path_addr
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,
data_path_addr=self.parameters.data_path_addr)
self.client.join_swarm(**join_arguments)
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

0 comments on commit fbc2750

Please sign in to comment.