diff --git a/lib/ansible/modules/cloud/docker/docker_swarm_service.py b/lib/ansible/modules/cloud/docker/docker_swarm_service.py index be4886f856..a3288cacc9 100644 --- a/lib/ansible/modules/cloud/docker/docker_swarm_service.py +++ b/lib/ansible/modules/cloud/docker/docker_swarm_service.py @@ -552,7 +552,7 @@ class DockerService(DockerBaseClass): self.mode = "replicated" self.user = "root" self.mounts = [] - self.configs = None + self.configs = [] self.secrets = [] self.constraints = [] self.networks = [] @@ -688,7 +688,7 @@ class DockerService(DockerBaseClass): s.mounts.append(service_m) s.configs = None - if ap['configs']: + if ap['configs'] is not None: s.configs = [] for param_m in ap['configs']: service_c = {} @@ -729,7 +729,7 @@ class DockerService(DockerBaseClass): differences.add('mode', parameter=self.mode, active=os.mode) if self.mounts != os.mounts: differences.add('mounts', parameter=self.mounts, active=os.mounts) - if self.configs != os.configs: + if self.configs is not None and self.configs != os.configs: differences.add('configs', parameter=self.configs, active=os.configs) if self.secrets != os.secrets: differences.add('secrets', parameter=self.secrets, active=os.secrets) diff --git a/test/integration/targets/docker_swarm_service/tasks/tests/options.yml b/test/integration/targets/docker_swarm_service/tasks/tests/options.yml index cf563c0531..b7323d608b 100644 --- a/test/integration/targets/docker_swarm_service/tasks/tests/options.yml +++ b/test/integration/targets/docker_swarm_service/tasks/tests/options.yml @@ -110,60 +110,64 @@ ## configs ######################################################### #################################################################### -# FIXME: Broken until #50606 is merged +- name: configs + docker_swarm_service: + name: "{{ service_name }}" + image: alpine:3.8 + configs: + - config_id: "{{ config_result_1.config_id }}" + config_name: "{{ config_name_1 }}" + filename: "/tmp/{{ config_name_1 }}.txt" + register: configs_1 -#- name: configs -# docker_swarm_service: -# name: "{{ service_name }}" -# image: alpine:3.8 -# configs: -# - config_id: "{{ config_result_1.config_id }}" -# config_name: "{{ config_name_1 }}" -# filename: "/tmp/{{ config_name_1 }}.txt" -# register: configs_1 -# -#- name: configs (idempotency) -# docker_swarm_service: -# name: "{{ service_name }}" -# image: alpine:3.8 -# configs: -# - config_id: "{{ config_result_1.config_id }}" -# config_name: "{{ config_name_1 }}" -# filename: "/tmp/{{ config_name_1 }}.txt" -# register: configs_2 -# -#- name: configs (add) -# docker_swarm_service: -# name: "{{ service_name }}" -# image: alpine:3.8 -# configs: -# - config_id: "{{ config_result_1.config_id }}" -# config_name: "{{ config_name_1 }}" -# filename: "/tmp/{{ config_name_1 }}.txt" -# - config_id: "{{ config_result_2.config_id }}" -# config_name: "{{ config_name_2 }}" -# filename: "/tmp/{{ config_name_2 }}.txt" -# register: configs_3 -# -#- name: configs (empty) -# docker_swarm_service: -# name: "{{ service_name }}" -# image: alpine:3.8 -# configs: [] -# register: configs_4 -# -#- assert: -# that: -# - configs_1 is changed -# - configs_2 is not changed -# - configs_3 is changed -# - configs_4 is changed -# when: docker_api_version is version('1.30', '>=') -#- assert: -# that: -# - configs_1 is failed -# - "('version is ' ~ docker_api_version ~'. Minimum version required is 1.30') in configs_1.msg" -# when: docker_api_version is version('1.30', '<') +- name: configs (idempotency) + docker_swarm_service: + name: "{{ service_name }}" + image: alpine:3.8 + configs: + - config_id: "{{ config_result_1.config_id }}" + config_name: "{{ config_name_1 }}" + filename: "/tmp/{{ config_name_1 }}.txt" + register: configs_2 + +- name: configs (add) + docker_swarm_service: + name: "{{ service_name }}" + image: alpine:3.8 + configs: + - config_id: "{{ config_result_1.config_id }}" + config_name: "{{ config_name_1 }}" + filename: "/tmp/{{ config_name_1 }}.txt" + - config_id: "{{ config_result_2.config_id }}" + config_name: "{{ config_name_2 }}" + filename: "/tmp/{{ config_name_2 }}.txt" + register: configs_3 + +- name: configs (empty) + docker_swarm_service: + name: "{{ service_name }}" + image: alpine:3.8 + configs: [] + register: configs_4 + +- name: cleanup + docker_swarm_service: + name: "{{ service_name }}" + state: absent + diff: no + +- assert: + that: + - configs_1 is changed + - configs_2 is not changed + - configs_3 is changed + - configs_4 is changed + when: docker_api_version is version('1.30', '>=') +- assert: + that: + - configs_1 is failed + - "('version is ' ~ docker_api_version ~'. Minimum version required is 1.30') in configs_1.msg" + when: docker_api_version is version('1.30', '<') #################################################################### ## constraints ##################################################### @@ -910,6 +914,12 @@ mounts: [] register: mounts_4 +- name: cleanup + docker_swarm_service: + name: "{{ service_name }}" + state: absent + diff: no + - assert: that: - mounts_1 is changed @@ -944,6 +954,12 @@ networks: [] register: networks_3 +- name: cleanup + docker_swarm_service: + name: "{{ service_name }}" + state: absent + diff: no + - assert: that: - networks_1 is changed @@ -1062,6 +1078,12 @@ mode: host register: publish_5 +- name: cleanup + docker_swarm_service: + name: "{{ service_name }}" + state: absent + diff: no + - assert: that: - publish_1 is changed @@ -1379,6 +1401,12 @@ secrets: [] register: secrets_4 +- name: cleanup + docker_swarm_service: + name: "{{ service_name }}" + state: absent + diff: no + - assert: that: - secrets_1 is changed