Skip to content

Commit

Permalink
Do not pass data_path_addr for older Docker SDK for Python versions. (#…
Browse files Browse the repository at this point in the history
…696) (#697)

(cherry picked from commit fbc2750)
  • Loading branch information
felixfontein authored Oct 14, 2023
1 parent 8db15e7 commit 5f413ac
Show file tree
Hide file tree
Showing 2 changed files with 15 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)."
17 changes: 12 additions & 5 deletions plugins/modules/docker_swarm.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@
like C(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
extends_documentation_fragment:
Expand Down Expand Up @@ -508,14 +509,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
try:
self.client.init_swarm(**init_arguments)
except APIError as exc:
Expand Down Expand Up @@ -567,11 +569,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 5f413ac

Please sign in to comment.