diff --git a/changelogs/fragments/696-docker_swarm-data_addr_path.yml b/changelogs/fragments/696-docker_swarm-data_addr_path.yml new file mode 100644 index 000000000..d776abb63 --- /dev/null +++ b/changelogs/fragments/696-docker_swarm-data_addr_path.yml @@ -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)." diff --git a/plugins/modules/docker_swarm.py b/plugins/modules/docker_swarm.py index e2138d60e..fb2ae83a7 100644 --- a/plugins/modules/docker_swarm.py +++ b/plugins/modules/docker_swarm.py @@ -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: @@ -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 @@ -534,7 +536,6 @@ 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, } @@ -542,6 +543,8 @@ def init_swarm(self): 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: @@ -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")