mirror of
https://github.com/containers/ansible-podman-collections.git
synced 2026-02-04 07:11:49 +00:00
Add idempotency for existing local volumes (#56)
This commit is contained in:
parent
d2bfe796f5
commit
80b2ae6abf
3 changed files with 80 additions and 13 deletions
|
|
@ -1731,16 +1731,23 @@ class PodmanContainerDiff:
|
||||||
|
|
||||||
def diffparam_volume(self):
|
def diffparam_volume(self):
|
||||||
before = self.info['mounts']
|
before = self.info['mounts']
|
||||||
|
before_local_vols = []
|
||||||
if before:
|
if before:
|
||||||
volumes = []
|
volumes = []
|
||||||
|
local_vols = []
|
||||||
for m in before:
|
for m in before:
|
||||||
if m['type'] != 'volume':
|
if m['type'] != 'volume':
|
||||||
volumes.append([m['source'], m['destination']])
|
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 = [":".join(v) for v in volumes]
|
||||||
|
before_local_vols = [":".join(v) for v in local_vols]
|
||||||
if self.params['volume'] is not None:
|
if self.params['volume'] is not None:
|
||||||
after = [":".join(v.split(":")[:2]) for v in self.params['volume']]
|
after = [":".join(v.split(":")[:2]) for v in self.params['volume']]
|
||||||
else:
|
else:
|
||||||
after = []
|
after = []
|
||||||
|
if before_local_vols:
|
||||||
|
after = list(set(after).difference(before_local_vols))
|
||||||
before, after = sorted(list(set(before))), sorted(list(set(after)))
|
before, after = sorted(list(set(before))), sorted(list(set(after)))
|
||||||
return self._diff_update_and_compare('volume', before, after)
|
return self._diff_update_and_compare('volume', before, after)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ RUN chmod a+rwx /start
|
||||||
EXPOSE 80
|
EXPOSE 80
|
||||||
EXPOSE 8080/tcp
|
EXPOSE 8080/tcp
|
||||||
|
|
||||||
VOLUME ["/data"]
|
VOLUME ["/data", "/data2"]
|
||||||
USER user
|
USER user
|
||||||
WORKDIR /work
|
WORKDIR /work
|
||||||
STOPSIGNAL 9
|
STOPSIGNAL 9
|
||||||
|
|
|
||||||
|
|
@ -117,6 +117,66 @@
|
||||||
assert:
|
assert:
|
||||||
that: test9 is not changed
|
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:
|
- containers.podman.podman_container:
|
||||||
name: idempotency1
|
name: idempotency1
|
||||||
state: absent
|
state: absent
|
||||||
|
|
@ -132,11 +192,11 @@
|
||||||
name: idempotency1
|
name: idempotency1
|
||||||
state: present
|
state: present
|
||||||
command: sleep 1h
|
command: sleep 1h
|
||||||
register: test10
|
register: test14
|
||||||
|
|
||||||
- name: check test10
|
- name: check test14
|
||||||
assert:
|
assert:
|
||||||
that: test10 is not changed
|
that: test14 is not changed
|
||||||
|
|
||||||
- containers.podman.podman_container:
|
- containers.podman.podman_container:
|
||||||
image: alpine
|
image: alpine
|
||||||
|
|
@ -145,30 +205,30 @@
|
||||||
volumes:
|
volumes:
|
||||||
- /opt:/data
|
- /opt:/data
|
||||||
command: sleep 1h
|
command: sleep 1h
|
||||||
register: test11
|
register: test15
|
||||||
|
|
||||||
- name: check test11
|
- name: check test15
|
||||||
assert:
|
assert:
|
||||||
that: test11 is changed
|
that: test15 is changed
|
||||||
|
|
||||||
- containers.podman.podman_container:
|
- containers.podman.podman_container:
|
||||||
image: alpine
|
image: alpine
|
||||||
name: idempotency1
|
name: idempotency1
|
||||||
state: present
|
state: present
|
||||||
command: sleep 1h
|
command: sleep 1h
|
||||||
register: test12
|
register: test16
|
||||||
|
|
||||||
- name: check test12
|
- name: check test16
|
||||||
assert:
|
assert:
|
||||||
that: test12 is changed
|
that: test16 is changed
|
||||||
|
|
||||||
- containers.podman.podman_container:
|
- containers.podman.podman_container:
|
||||||
image: alpine
|
image: alpine
|
||||||
name: idempotency1
|
name: idempotency1
|
||||||
state: present
|
state: present
|
||||||
command: sleep 1h
|
command: sleep 1h
|
||||||
register: test13
|
register: test17
|
||||||
|
|
||||||
- name: check test13
|
- name: check test17
|
||||||
assert:
|
assert:
|
||||||
that: test13 is not changed
|
that: test17 is not changed
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue