From c75da35595b9d0c6fdc31d27e497b89787ad566b Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Sat, 9 Mar 2019 21:28:04 +0100 Subject: [PATCH] Removing a swarm node does not work with docker-py < 2.4.0, since it calls client.inspect_node(). (#53565) For the same reason, docker_node requires docker >= 2.4.0. --- .../fragments/53129-docker_swarm-older-docker-py.yaml | 2 +- lib/ansible/modules/cloud/docker/docker_swarm.py | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/changelogs/fragments/53129-docker_swarm-older-docker-py.yaml b/changelogs/fragments/53129-docker_swarm-older-docker-py.yaml index 460eb0cef6..db2fae14c2 100644 --- a/changelogs/fragments/53129-docker_swarm-older-docker-py.yaml +++ b/changelogs/fragments/53129-docker_swarm-older-docker-py.yaml @@ -1,2 +1,2 @@ bugfixes: -- "docker_swarm - now supports docker-py 1.10.0 and newer, instead only docker 2.6.0 and newer." +- "docker_swarm - now supports docker-py 1.10.0 and newer for most operations, instead only docker 2.6.0 and newer." diff --git a/lib/ansible/modules/cloud/docker/docker_swarm.py b/lib/ansible/modules/cloud/docker/docker_swarm.py index a4b410ac49..6e172acffc 100644 --- a/lib/ansible/modules/cloud/docker/docker_swarm.py +++ b/lib/ansible/modules/cloud/docker/docker_swarm.py @@ -52,6 +52,7 @@ options: - Set to C(join), to join an existing cluster. - Set to C(absent), to leave an existing cluster. - Set to C(remove), to remove an absent node from the cluster. + Note that removing requires docker-py >= 2.4.0. - Set to C(inspect) to display swarm informations. type: str required: yes @@ -530,6 +531,10 @@ class SwarmManager(DockerBaseClass): self.results['changed'] = True +def _detect_remove_operation(client): + return client.module.params['state'] == 'remove' + + def main(): argument_spec = dict( advertise_addr=dict(type='str'), @@ -569,6 +574,11 @@ def main(): ca_force_rotate=dict(docker_py_version='2.6.0', docker_api_version='1.30'), autolock_managers=dict(docker_py_version='2.6.0'), log_driver=dict(docker_py_version='2.6.0'), + remove_operation=dict( + docker_py_version='2.4.0', + detect_usage=_detect_remove_operation, + usage_msg='remove swarm nodes' + ), ) client = AnsibleDockerSwarmClient(