diff --git a/plugins/modules/podman_container.py b/plugins/modules/podman_container.py index 8b17cc7f..753632fa 100644 --- a/plugins/modules/podman_container.py +++ b/plugins/modules/podman_container.py @@ -1731,16 +1731,23 @@ def diffparam_uts(self): def diffparam_volume(self): before = self.info['mounts'] + before_local_vols = [] if before: volumes = [] + local_vols = [] for m in before: if m['type'] != 'volume': volumes.append([m['source'], m['destination']]) + elif m['type'] == 'volume': + local_vols.append([m['name'], m['destination']]) before = [":".join(v) for v in volumes] + before_local_vols = [":".join(v) for v in local_vols] if self.params['volume'] is not None: after = [":".join(v.split(":")[:2]) for v in self.params['volume']] else: after = [] + if before_local_vols: + after = list(set(after).difference(before_local_vols)) before, after = sorted(list(set(before))), sorted(list(set(after))) return self._diff_update_and_compare('volume', before, after) diff --git a/tests/integration/targets/podman_container/files/Dockerfile b/tests/integration/targets/podman_container/files/Dockerfile index 80a53721..822662f4 100644 --- a/tests/integration/targets/podman_container/files/Dockerfile +++ b/tests/integration/targets/podman_container/files/Dockerfile @@ -18,7 +18,7 @@ RUN chmod a+rwx /start EXPOSE 80 EXPOSE 8080/tcp -VOLUME ["/data"] +VOLUME ["/data", "/data2"] USER user WORKDIR /work STOPSIGNAL 9 diff --git a/tests/integration/targets/podman_container/tasks/idem_volumes.yml b/tests/integration/targets/podman_container/tasks/idem_volumes.yml index e92a3fe2..387decc9 100644 --- a/tests/integration/targets/podman_container/tasks/idem_volumes.yml +++ b/tests/integration/targets/podman_container/tasks/idem_volumes.yml @@ -117,6 +117,66 @@ assert: that: test9 is not changed +- name: Create volumes + shell: | + podman volume inspect local_volume1 || podman volume create local_volume1 + podman volume inspect local_volume2 || podman volume create local_volume2 + +- containers.podman.podman_container: + image: "{{ idem_image }}" + name: idempotency + state: present + command: 1h + volumes: + - "/opt:/anotherdir" + - "local_volume1:/data" + register: test10 + +- name: check test10 + assert: + that: test10 is changed + +- containers.podman.podman_container: + image: "{{ idem_image }}" + name: idempotency + state: present + command: 1h + volumes: + - "/opt:/anotherdir" + - "local_volume1:/data" + register: test11 + +- name: check test11 + assert: + that: test11 is not changed + +- containers.podman.podman_container: + image: "{{ idem_image }}" + name: idempotency + state: present + command: 1h + volumes: + - "/opt:/anotherdir" + - "local_volume2:/data" + register: test12 + +- name: check test12 + assert: + that: test12 is changed + +- containers.podman.podman_container: + image: "{{ idem_image }}" + name: idempotency + state: present + command: 1h + volumes: + - "/opt:/anotherdir" + register: test13 + +- name: check test13 + assert: + that: test13 is not changed + - containers.podman.podman_container: name: idempotency1 state: absent @@ -132,11 +192,11 @@ name: idempotency1 state: present command: sleep 1h - register: test10 + register: test14 -- name: check test10 +- name: check test14 assert: - that: test10 is not changed + that: test14 is not changed - containers.podman.podman_container: image: alpine @@ -145,30 +205,30 @@ volumes: - /opt:/data command: sleep 1h - register: test11 + register: test15 -- name: check test11 +- name: check test15 assert: - that: test11 is changed + that: test15 is changed - containers.podman.podman_container: image: alpine name: idempotency1 state: present command: sleep 1h - register: test12 + register: test16 -- name: check test12 +- name: check test16 assert: - that: test12 is changed + that: test16 is changed - containers.podman.podman_container: image: alpine name: idempotency1 state: present command: sleep 1h - register: test13 + register: test17 -- name: check test13 +- name: check test17 assert: - that: test13 is not changed + that: test17 is not changed