diff --git a/changelogs/fragments/58039-docker_swarm_service-fix-resource-lookup.yaml b/changelogs/fragments/58039-docker_swarm_service-fix-resource-lookup.yaml new file mode 100644 index 0000000000..63daa74a74 --- /dev/null +++ b/changelogs/fragments/58039-docker_swarm_service-fix-resource-lookup.yaml @@ -0,0 +1,2 @@ +bugfixes: + - docker_swarm_service - fix resource lookup if mounts.source="". diff --git a/lib/ansible/modules/cloud/docker/docker_swarm_service.py b/lib/ansible/modules/cloud/docker/docker_swarm_service.py index 296420a5e6..96cc5f8aa1 100644 --- a/lib/ansible/modules/cloud/docker/docker_swarm_service.py +++ b/lib/ansible/modules/cloud/docker/docker_swarm_service.py @@ -2230,7 +2230,7 @@ class DockerServiceManager(object): (key.lower(), value) for key, value in driver_config.items() ) or None ds.mounts.append({ - 'source': mount_data['Source'], + 'source': mount_data.get('Source', ''), 'type': mount_data['Type'], 'target': mount_data['Target'], 'readonly': mount_data.get('ReadOnly'), diff --git a/test/integration/targets/docker_swarm_service/tasks/tests/mounts.yml b/test/integration/targets/docker_swarm_service/tasks/tests/mounts.yml index e2c2029329..5063648e61 100644 --- a/test/integration/targets/docker_swarm_service/tasks/tests/mounts.yml +++ b/test/integration/targets/docker_swarm_service/tasks/tests/mounts.yml @@ -509,6 +509,53 @@ - "'Minimum version required' in mounts_tmpfs_size_1.msg" when: docker_py_version is version('2.6.0', '<') +#################################################################### +## mounts.source ################################################### +#################################################################### + +- name: mounts.source (empty for tmpfs) + docker_swarm_service: + name: "{{ service_name }}" + image: alpine:3.8 + resolve_image: no + command: '/bin/sh -v -c "sleep 10m"' + mounts: + - source: "" + target: "/tmp/{{ volume_name_1 }}" + type: "tmpfs" + register: mounts_tmpfs_source_1 + ignore_errors: yes + +- name: mounts.source (empty for tmpfs idempotency) + docker_swarm_service: + name: "{{ service_name }}" + image: alpine:3.8 + resolve_image: no + command: '/bin/sh -v -c "sleep 10m"' + mounts: + - source: "" + target: "/tmp/{{ volume_name_1 }}" + type: "tmpfs" + register: mounts_tmpfs_source_2 + ignore_errors: yes + +- name: cleanup + docker_swarm_service: + name: "{{ service_name }}" + state: absent + diff: no + +- assert: + that: + - mounts_tmpfs_source_1 is changed + - mounts_tmpfs_source_2 is not changed + when: docker_py_version is version('2.6.0', '>=') +- assert: + that: + - mounts_tmpfs_source_1 is failed + - "'Minimum version required' in mounts_tmpfs_source_1.msg" + when: docker_py_version is version('2.6.0', '<') + #################################################################### #################################################################### ####################################################################