From c67f4290e61cdf08fd7c55a5654a71b78a1973c6 Mon Sep 17 00:00:00 2001 From: Dave Bendit Date: Fri, 14 Dec 2018 13:20:48 -0600 Subject: [PATCH] [docker_volume] Checking option minimal versions (#49839) Fixes #38833 --- ...8833-docker_volume-option-minimum-versions | 3 +++ .../modules/cloud/docker/docker_volume.py | 19 +++++++++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) create mode 100644 changelogs/fragments/38833-docker_volume-option-minimum-versions diff --git a/changelogs/fragments/38833-docker_volume-option-minimum-versions b/changelogs/fragments/38833-docker_volume-option-minimum-versions new file mode 100644 index 0000000000..63ea29ae27 --- /dev/null +++ b/changelogs/fragments/38833-docker_volume-option-minimum-versions @@ -0,0 +1,3 @@ +--- +minor_changes: + - "docker_volume - option minimal versions now checked. (https://github.com/ansible/ansible/issues/38833)" diff --git a/lib/ansible/modules/cloud/docker/docker_volume.py b/lib/ansible/modules/cloud/docker/docker_volume.py index c543ab4768..8c47cb8370 100644 --- a/lib/ansible/modules/cloud/docker/docker_volume.py +++ b/lib/ansible/modules/cloud/docker/docker_volume.py @@ -216,10 +216,15 @@ class DockerVolumeManager(object): if not self.existing_volume: if not self.check_mode: try: - resp = self.client.create_volume(self.parameters.volume_name, - driver=self.parameters.driver, - driver_opts=self.parameters.driver_options, - labels=self.parameters.labels) + params = dict( + driver=self.parameters.driver, + driver_opts=self.parameters.driver_options, + ) + + if self.parameters.labels is not None: + params['labels'] = self.parameters.labels + + resp = self.client.create_volume(self.parameters.volume_name, **params) self.existing_volume = self.client.inspect_volume(resp['Name']) except APIError as e: self.client.fail(text_type(e)) @@ -275,11 +280,17 @@ def main(): debug=dict(type='bool', default=False) ) + option_minimal_versions = dict( + labels=dict(docker_py_version='1.10.0', docker_api_version='1.23'), + ) + client = AnsibleDockerClient( argument_spec=argument_spec, supports_check_mode=True, min_docker_version='1.10.0', + min_docker_api_version='1.21', # "The docker server >= 1.9.0" + option_minimal_versions=option_minimal_versions, ) cm = DockerVolumeManager(client)