From 2773e215f7281eb4e1af456e437c41ec8545b398 Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Mon, 11 Mar 2019 21:20:30 +0100 Subject: [PATCH] [2.7] docker_swarm: removing nodes requires docker >= 2.4.0 (#53592) * 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. (cherry picked from commit c75da35595b9d0c6fdc31d27e497b89787ad566b) * Reconstructing a change from devel which is required to make usage detection work this way. --- .../fragments/53129-docker_swarm-older-docker-py.yaml | 2 +- lib/ansible/module_utils/docker_common.py | 2 +- lib/ansible/modules/cloud/docker/docker_container.py | 2 +- lib/ansible/modules/cloud/docker/docker_swarm.py | 10 ++++++++++ 4 files changed, 13 insertions(+), 3 deletions(-) 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/module_utils/docker_common.py b/lib/ansible/module_utils/docker_common.py index 51afbba187..ee71de7f8d 100644 --- a/lib/ansible/module_utils/docker_common.py +++ b/lib/ansible/module_utils/docker_common.py @@ -442,7 +442,7 @@ class AnsibleDockerClient(Client): if not data['supported']: # Test whether option is specified if 'detect_usage' in data: - used = data['detect_usage']() + used = data['detect_usage'](self) else: used = self.module.params.get(option) is not None if used and 'default' in self.module.argument_spec[option]: diff --git a/lib/ansible/modules/cloud/docker/docker_container.py b/lib/ansible/modules/cloud/docker/docker_container.py index 1d6a04151b..727a4f1774 100644 --- a/lib/ansible/modules/cloud/docker/docker_container.py +++ b/lib/ansible/modules/cloud/docker/docker_container.py @@ -2234,7 +2234,7 @@ class AnsibleDockerClientContainer(AnsibleDockerClient): self.comparisons = comparisons def __init__(self, **kwargs): - def detect_ipvX_address_usage(): + def detect_ipvX_address_usage(client): ''' Helper function to detect whether any specified network uses ipv4_address or ipv6_address ''' diff --git a/lib/ansible/modules/cloud/docker/docker_swarm.py b/lib/ansible/modules/cloud/docker/docker_swarm.py index 13e91c7679..dd1df2a070 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 @@ -553,6 +554,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'), @@ -592,6 +597,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 = AnsibleDockerClient(