Debian Codegraph @

ansible_collections/containers/podman/tests/integration/targets/podman_prune/tasks/main.yml

raw
1 - name: Create random names
2 ansible.builtin.set_fact:
3 cname: "{{ 'ansible-container-%0x' % ((2**32) | random) }}"
4 nname: "{{ 'ansible-network-%0x' % ((2**32) | random) }}"
5 vname: "{{ 'ansible-volume-%0x' % ((2**32) | random) }}"
6
7 - name: Test podman_prune module
8 block:
9 # Create objects to be pruned
10 - name: Create container
11 containers.podman.podman_container:
12 executable: "{{ test_executable | default('podman') }}"
13 name: "{{ cname }}"
14 image: quay.io/podman/hello:latest
15 state: present
16 register: container
17
18 - name: Create network
19 containers.podman.podman_network:
20 executable: "{{ test_executable | default('podman') }}"
21 name: "{{ nname }}"
22 state: present
23 register: network
24
25 - name: Create volume
26 containers.podman.podman_volume:
27 executable: "{{ test_executable | default('podman') }}"
28 name: "{{ vname }}"
29 state: present
30 register: volume
31
32 # Prune objects
33 - name: Prune objects
34 containers.podman.podman_prune:
35 executable: "{{ test_executable | default('podman') }}"
36 container: true
37 network: true
38 volume: true
39
40 - name: Check if container exists
41 containers.podman.podman_container_info:
42 executable: "{{ test_executable | default('podman') }}"
43 register: container_exists
44
45 - name: Check if podman network exists
46 containers.podman.podman_network_info:
47 register: network_exists
48
49 - name: Check if podman volume exists
50 containers.podman.podman_volume_info:
51 executable: "{{ test_executable | default('podman') }}"
52 register: volume_exists
53
54 - name: Verify assertions for network, container and volume
55 ansible.builtin.assert:
56 that:
57 # containers
58 - container.container.Id not in container_exists.containers | map(attribute='Name') | list | flatten
59 # networks
60 - network.network.name not in network_exists.networks | map(attribute='id') | list | flatten
61 # volumes
62 - volume.volume.Name not in volume_exists.volumes | map(attribute='Name') | list | flatten
63
64 # Test with filters
65 - name: Prune objects with filters
66 containers.podman.podman_prune:
67 executable: "{{ test_executable | default('podman') }}"
68 image: true
69 image_filters:
70 dangling_only: false
71 external: true
72
73 - name: Check if image exists
74 containers.podman.podman_image_info:
75 executable: "{{ test_executable | default('podman') }}"
76 register: image_exists
77
78 - name: Verify assertions for image (with filters)
79 ansible.builtin.assert:
80 that:
81 - image_exists.images | length == 0
82
83 - name: Create container
84 containers.podman.podman_container:
85 executable: "{{ test_executable | default('podman') }}"
86 name: "{{ cname }}"
87 image: quay.io/podman/hello:latest
88 state: present
89 register: container_system
90
91 - name: Create network
92 containers.podman.podman_network:
93 executable: "{{ test_executable | default('podman') }}"
94 name: "{{ nname }}"
95 state: present
96 register: network_system
97
98 - name: Create volume
99 containers.podman.podman_volume:
100 executable: "{{ test_executable | default('podman') }}"
101 name: "{{ vname }}"
102 state: present
103 register: volume_system
104
105 - name: System prune
106 containers.podman.podman_prune:
107 executable: "{{ test_executable | default('podman') }}"
108 system: true
109 system_all: true
110 system_volumes: true
111
112 - name: Check if container exists
113 containers.podman.podman_container_info:
114 executable: "{{ test_executable | default('podman') }}"
115 register: container_system_exists
116
117 - name: Check if podman network exists
118 containers.podman.podman_network_info:
119 executable: "{{ test_executable | default('podman') }}"
120 register: network_system_exists
121
122 - name: Check if podman volume exists
123 containers.podman.podman_volume_info:
124 executable: "{{ test_executable | default('podman') }}"
125 register: volume_system_exists
126
127 - name: Check if image exists
128 containers.podman.podman_image_info:
129 executable: "{{ test_executable | default('podman') }}"
130 register: image_system_exists
131
132 - name: Verify assertions for system
133 ansible.builtin.assert:
134 that:
135 # container
136 - container_system.container.Id not in container_system_exists.containers | map(attribute='Name') | list | flatten
137 # networks
138 - network_system.network.name not in network_system_exists.networks | map(attribute='id') | list | flatten
139 # volumes
140 - volume_system.volume.Name not in volume_system_exists.volumes | map(attribute='Name') | list | flatten
141 # images
142 - image_system_exists.images | length == 0
143
144 # Idempotency - Test "Total reclaimed space: 0B" does not report changed
145 - name: Prune objects
146 containers.podman.podman_prune:
147 executable: "{{ test_executable | default('podman') }}"
148 system: true
149
150 - name: Prune objects - 2nd time
151 containers.podman.podman_prune:
152 executable: "{{ test_executable | default('podman') }}"
153 system: true
154 register: podman_prune_result
155
156 - name: Assert that result.changed is false
157 ansible.builtin.assert:
158 that:
159 - podman_prune_result.system.changed == false
160
161 always:
162 - name: Cleanup
163 ansible.builtin.command: podman system prune -a -f --volumes
164 ignore_errors: true