Debian Codegraph @

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

raw
1 - name: Test podman_image
2 block:
3 - name: List all images on host before test
4 containers.podman.podman_image_info:
5
6 - name: Remove images for test
7 containers.podman.podman_image:
8 name: "{{ item }}"
9 state: absent
10 loop:
11 - quay.io/sshnaidm1/alpine-sh
12 - docker.io/alpine
13 - docker.io/library/ubuntu
14 - docker.io/library/alpine
15
16 - name: Pull image
17 containers.podman.podman_image:
18 executable: "{{ test_executable | default('podman') }}"
19 name: quay.io/sshnaidm1/alpine-sh
20 register: pull1
21
22 - name: Pull image again
23 containers.podman.podman_image:
24 executable: "{{ test_executable | default('podman') }}"
25 name: quay.io/sshnaidm1/alpine-sh
26 register: pull2
27
28 - name: Pull image from docker.io with short url
29 containers.podman.podman_image:
30 executable: "{{ test_executable | default('podman') }}"
31 name: docker.io/alpine
32 register: pull3
33
34 - name: Pull image from docker.io with short url again
35 containers.podman.podman_image:
36 executable: "{{ test_executable | default('podman') }}"
37 name: docker.io/alpine
38 register: pull4
39
40 - name: Pull image from docker.io with official/normalised url again
41 containers.podman.podman_image:
42 executable: "{{ test_executable | default('podman') }}"
43 name: docker.io/library/alpine
44 register: pull5
45
46 - name: Pull image for testing image deletion with image id
47 containers.podman.podman_image:
48 executable: "{{ test_executable | default('podman') }}"
49 name: docker.io/library/ubuntu
50 register: pull6
51
52 - name: List images
53 command: podman image ls
54 register: images
55
56 - name: Ensure image were pulled properly
57 assert:
58 that:
59 - pull1 is changed
60 - pull1.podman_actions is defined
61 - pull2 is not changed
62 - pull3 is changed
63 - pull4 is not changed
64 - pull5 is not changed
65 - pull6 is changed
66 - "'alpine-sh' in images.stdout"
67 - "'library/alpine' in images.stdout"
68 - "'library/ubuntu' in images.stdout"
69
70 - name: add another tag (repository url)
71 command:
72 argv:
73 - podman
74 - tag
75 - quay.io/sshnaidm1/alpine-sh
76 - quay.io/coreos/library/alpine-sh
77
78 - name: Remove image (tag)
79 containers.podman.podman_image:
80 executable: "{{ test_executable | default('podman') }}"
81 name: quay.io/sshnaidm1/alpine-sh
82 state: absent
83 register: rmi1
84
85 - name: Remove image again
86 containers.podman.podman_image:
87 executable: "{{ test_executable | default('podman') }}"
88 name: quay.io/sshnaidm1/alpine-sh
89 state: absent
90 register: rmi2
91
92 - name: Remove image using new repository url
93 containers.podman.podman_image:
94 executable: "{{ test_executable | default('podman') }}"
95 name: quay.io/coreos/library/alpine-sh
96 state: absent
97 register: rmi3
98
99 - name: Remove docker.io image using short url
100 containers.podman.podman_image:
101 executable: "{{ test_executable | default('podman') }}"
102 name: docker.io/alpine
103 state: absent
104 register: rmi4
105
106 - name: Try to remove docker.io image using normalised url
107 containers.podman.podman_image:
108 executable: "{{ test_executable | default('podman') }}"
109 name: docker.io/library/alpine
110 state: absent
111 register: rmi5
112
113 - name: Get image id of the target image
114 containers.podman.podman_image_info:
115 executable: "{{ test_executable | default('podman') }}"
116 name: docker.io/library/ubuntu
117 register: imageinfo
118
119 - name: Remove an image with image id
120 containers.podman.podman_image:
121 executable: "{{ test_executable | default('podman') }}"
122 name: "{{ item.Id }}"
123 state: absent
124 loop: "{{ imageinfo.images }}"
125 register: rmi6
126
127 - name: List images
128 command: podman image ls
129 register: images
130
131 - name: Ensure image were removed properly
132 assert:
133 that:
134 - rmi1 is changed
135 - rmi2 is not changed
136 - rmi3 is changed
137 - rmi4 is changed
138 - rmi5 is not changed
139 - rmi6 is changed
140 - "'alpine-sh' not in images.stdout"
141 - "'library/ubuntu' not in images.stdout"
142
143 - name: Pull a specific version of an image
144 containers.podman.podman_image:
145 executable: "{{ test_executable | default('podman') }}"
146 name: quay.io/coreos/etcd
147 tag: v3.3.11
148 register: specific_image1
149
150 - name: Pull a specific version of an image again
151 containers.podman.podman_image:
152 executable: "{{ test_executable | default('podman') }}"
153 name: quay.io/coreos/etcd
154 tag: v3.3.11
155 register: specific_image2
156
157 - name: List images
158 command: podman image ls
159 register: images
160
161 - name: Ensure specific image was pulled properly
162 assert:
163 that:
164 - specific_image1 is changed
165 - specific_image2 is not changed
166 - "'v3.3.11' in images.stdout"
167
168 - name: Get info about pulled image
169 containers.podman.podman_image_info:
170 executable: "{{ test_executable | default('podman') }}"
171 name: quay.io/coreos/etcd:v3.3.11
172 register: sha_image_info
173
174 - name: Pull image with SHA256 tag
175 containers.podman.podman_image:
176 executable: "{{ test_executable | default('podman') }}"
177 name: "quay.io/coreos/etcd@{{ sha_image_info.images.0.Digest }}" #quay.io/coreos/coreos-installer:latest
178 state: present
179
180 - name: Create a build directory with a subdirectory
181 file:
182 path: /var/tmp/build/subdir
183 state: directory
184
185 - name: Copy Containerfile
186 copy:
187 src: Containerfile
188 dest: /var/tmp/build/Dockerfile
189
190 - name: Build OCI image
191 containers.podman.podman_image:
192 executable: "{{ test_executable | default('podman') }}"
193 name: testimage
194 path: /var/tmp/build
195 register: oci_build1
196
197 - name: Build OCI image again
198 containers.podman.podman_image:
199 executable: "{{ test_executable | default('podman') }}"
200 name: testimage
201 path: /var/tmp/build
202 register: oci_build2
203
204 - name: Build OCI image from a directory without Containerfile (should fail)
205 containers.podman.podman_image:
206 executable: "{{ test_executable | default('podman') }}"
207 name: testimage2
208 path: /var/tmp/build/subdir
209 register: oci_build3
210 ignore_errors: true
211
212 - name: Build OCI image, point to location of Containerfile without path
213 containers.podman.podman_image:
214 executable: "{{ test_executable | default('podman') }}"
215 name: testimage2
216 state: build
217 build:
218 file: /var/tmp/build/Dockerfile
219 register: oci_build4
220
221 - name: Build OCI image, point to location of Containerfile and path
222 containers.podman.podman_image:
223 executable: "{{ test_executable | default('podman') }}"
224 name: testimage3
225 path: /var/tmp/build
226 build:
227 file: /var/tmp/build/Dockerfile
228 register: oci_build5
229
230 - name: Build OCI image with no Containerfile and path
231 containers.podman.podman_image:
232 executable: "{{ test_executable | default('podman') }}"
233 name: testimage5x
234 state: build
235 build:
236 format: oci
237 register: oci_build6
238 ignore_errors: true
239
240 - name: Build OCI image testimage6 twice with the same Containerfile
241 containers.podman.podman_image:
242 executable: "{{ test_executable | default('podman') }}"
243 name: testimage6
244 state: build
245 build:
246 format: oci
247 container_file: |-
248 FROM quay.io/sshnaidm1/alpine-sh
249 register: oci_build7
250 loop: [0, 1]
251
252 - name: Build OCI image testimage6 with a different Containerfile
253 containers.podman.podman_image:
254 executable: "{{ test_executable | default('podman') }}"
255 name: testimage6
256 state: build
257 build:
258 format: oci
259 container_file: |-
260 FROM docker.io/alpine
261 register: oci_build8
262
263 - name: Inspect first image
264 containers.podman.podman_image_info:
265 executable: "{{ test_executable | default('podman') }}"
266 name: testimage
267 register: testimage_info
268
269 - name: Inspect second image
270 containers.podman.podman_image_info:
271 executable: "{{ test_executable | default('podman') }}"
272 name: testimage2
273 register: testimage2_info
274
275 - name: Ensure OCI images were built properly
276 assert:
277 that:
278 - oci_build1 is changed
279 - oci_build2 is not changed
280 - oci_build3 is not changed
281 - oci_build3 is failed
282 - oci_build4 is success
283 - oci_build5 is success
284 - oci_build6 is failed
285 # The following line tests that building an image twice with
286 # the same Containerfile doesn't rebuild the image.
287 - oci_build7.results[1] is not changed
288 # oci_build8 tests that building an image with the same name
289 # but a different Containerfile results in a new image being
290 # built.
291 - oci_build8 is changed
292 - "'localhost/testimage:latest' in testimage_info.images[0]['RepoTags'][0]"
293 - "'localhost/testimage2:latest' in testimage2_info.images[0]['RepoTags'][0]"
294 - "'no such file or directory' in oci_build3.msg"
295
296 - name: Build Docker image
297 containers.podman.podman_image:
298 executable: "{{ test_executable | default('podman') }}"
299 name: dockerimage
300 path: /var/tmp/build
301 build:
302 format: docker
303 register: docker_build1
304
305 - name: Build Docker image again
306 containers.podman.podman_image:
307 executable: "{{ test_executable | default('podman') }}"
308 name: dockerimage
309 path: /var/tmp/build
310 build:
311 format: docker
312 register: docker_build2
313
314 - name: Inspect built image
315 containers.podman.podman_image_info:
316 executable: "{{ test_executable | default('podman') }}"
317 name: dockerimage
318 register: dockerimage_info
319
320 - name: Ensure Docker image was built properly
321 assert:
322 that:
323 - docker_build1 is changed
324 - docker_build2 is not changed
325 - "'localhost/dockerimage:latest' in dockerimage_info.images[0]['RepoTags'][0]"
326
327 - name: push image that doesn't exit to nowhere
328 containers.podman.podman_image:
329 executable: "{{ test_executable | default('podman') }}"
330 name: bad_image
331 pull: false
332 push: true
333 register: bad_push
334 ignore_errors: true
335
336 - name: Ensure that Image failed correctly.
337 assert:
338 that:
339 - "bad_push is failed"
340 - "bad_push is not changed"
341 - "'Image bad_image:latest not found' in bad_push.msg"
342 - "'pull is disabled' in bad_push.msg"
343
344 - name: Pull an image for a specific CPU architecture
345 containers.podman.podman_image:
346 executable: "{{ test_executable | default('podman') }}"
347 name: docker.io/library/ubuntu
348 arch: amd64
349 register: pull_arch1
350
351 - name: Pull the same image for the same CPU architecture
352 containers.podman.podman_image:
353 executable: "{{ test_executable | default('podman') }}"
354 name: docker.io/library/ubuntu
355 arch: amd64
356 register: pull_arch2
357
358 - name: Pull the same image but for another CPU architecture
359 containers.podman.podman_image:
360 executable: "{{ test_executable | default('podman') }}"
361 name: docker.io/library/ubuntu
362 arch: arm
363 register: pull_arch3
364
365 - name: Ensure the result of pulling image for another CPU architecture
366 assert:
367 that:
368 - "pull_arch2 is not changed"
369 - "pull_arch3 is changed"
370
371 - name: Get the image info
372 containers.podman.podman_image_info:
373 executable: "{{ test_executable | default('podman') }}"
374 name: docker.io/library/ubuntu
375 register: imageinfo_arch
376
377 - name: Ensure the CPU architecture of the image is as expected
378 assert:
379 that:
380 - item.Architecture == "arm"
381 loop: "{{ imageinfo_arch.images }}"
382
383 - name: Pull an image for a specific platform
384 containers.podman.podman_image:
385 executable: "{{ test_executable | default('podman') }}"
386 name: quay.io/coreos/etcd:v3.5.27
387 platform: linux/amd64
388 register: pull_platform1
389
390 - name: Pull the same image for the same platform
391 containers.podman.podman_image:
392 executable: "{{ test_executable | default('podman') }}"
393 name: quay.io/coreos/etcd:v3.5.27
394 platform: linux/amd64
395 register: pull_platform2
396
397 - name: Ensure platform pull is idempotent
398 assert:
399 that:
400 - pull_platform1 is changed
401 - pull_platform2 is not changed
402
403 - name: Build Docker image
404 containers.podman.podman_image:
405 executable: "{{ test_executable | default('podman') }}"
406 name: quay.io/testing/testimage
407 path: /var/tmp/build
408 register: build_image1
409
410 - name: Build Docker image - 2
411 containers.podman.podman_image:
412 executable: "{{ test_executable | default('podman') }}"
413 name: quay.io/testing/testimage:draft
414 path: /var/tmp/build
415
416 - name: Build Docker image
417 containers.podman.podman_image:
418 executable: "{{ test_executable | default('podman') }}"
419 name: testimage2:testtag
420 path: /var/tmp/build
421 register: build_image2
422
423 - name: Create a temporary directory for custom image
424 file:
425 path: /tmp/containers_test
426 state: directory
427
428 - name: Build image from a given Containerfile
429 containers.podman.podman_image:
430 executable: "{{ test_executable | default('podman') }}"
431 name: testimage2:customfile
432 path: /tmp/containers_test
433 build:
434 container_file: |-
435 FROM quay.io/sshnaidm1/alpine-sh
436 RUN echo "Hello World" > /tmp/hello.txt
437 register: build_custom1
438
439 - name: Build image from a given Containerfile w/o path
440 containers.podman.podman_image:
441 executable: "{{ test_executable | default('podman') }}"
442 name: testimage2:customfile2
443 state: build
444 build:
445 container_file: |-
446 FROM quay.io/sshnaidm1/alpine-sh
447 RUN echo "Hello2 World" > /tmp/hello2.txt
448 force: true
449 register: build_custom2
450
451 - name: Build image from a given Containerfile and file (fail)
452 containers.podman.podman_image:
453 executable: "{{ test_executable | default('podman') }}"
454 name: testimage2:failme
455 state: build
456 build:
457 container_file: |-
458 FROM quay.io/sshnaidm1/alpine-sh
459 RUN echo "Hello2 World" > /tmp/hello2.txt
460 file: /var/tmp/build/Dockerfile
461 force: true
462 register: fail_custom_image
463 ignore_errors: true
464
465 - name: Check if image was built properly
466 assert:
467 that:
468 - build_custom1 is changed
469 - build_custom2 is changed
470 - fail_custom_image is failed
471
472 - include_tasks: idem_push.yml
473
474 - name: Create a Quadlet for image with filename
475 containers.podman.podman_image:
476 executable: "{{ test_executable | default('podman') }}"
477 name: quay.io/coreos/coreos-installer:latest
478 state: quadlet
479 arch: x86_64
480 quadlet_dir: /tmp
481 quadlet_filename: customfile
482
483 - name: Check if files exists
484 stat:
485 path: /tmp/customfile.image
486 register: quadlet_file_custom
487
488 - name: Fail if no file is present or wrong mode
489 assert:
490 that:
491 - quadlet_file_custom.stat.exists
492 - quadlet_file_custom.stat.mode == '0640'
493
494 - name: Create quadlet image file
495 containers.podman.podman_image:
496 executable: "{{ test_executable | default('podman') }}"
497 name: quay.io/coreos/coreos-installer:latest
498 state: quadlet
499 arch: x86_64
500 ca_cert_dir: /etc/docker/certs.d
501 username: user
502 password: pass
503 validate_certs: false
504 quadlet_dir: /tmp/
505 quadlet_file_mode: '0644'
506 quadlet_options:
507 - "ImageTag=quay.io/coreos/coreos-installer:12345"
508 - "AllTags=true"
509 - |-
510 [Install]
511 WantedBy=default.target
512
513 - name: Check if files exists
514 stat:
515 path: /tmp/coreos-installer.image
516 register: quadlet_file
517
518 - name: Check output is correct for Quadlet image in /tmp/coreos-installer.image file
519 assert:
520 that:
521 - quadlet_file.stat.exists
522
523 - name: Check quadlet file mode is correct
524 assert:
525 that:
526 - quadlet_file.stat.mode == '0644'
527
528 - name: Check for the existence of lines in /tmp/coreos-installer.image
529 lineinfile:
530 path: /tmp/coreos-installer.image
531 line: "{{ item }}"
532 state: present
533 check_mode: yes
534 register: line_check
535 loop:
536 - "[Image]"
537 - "Image=quay.io/coreos/coreos-installer:latest"
538 - "ImageTag=quay.io/coreos/coreos-installer:12345"
539 - "AllTags=true"
540 - "WantedBy=default.target"
541 - "Arch=x86_64"
542 - "CertDir=/etc/docker/certs.d"
543 - "Creds=user:pass"
544 - "TLSVerify=false"
545 loop_control:
546 label: "{{ item }}"
547
548 - name: Fail the task if any line is not present
549 fail:
550 msg: "The following line is not present in /tmp/coreos-installer.image: {{ item.item }}"
551 when: item.changed
552 loop: "{{ line_check.results }}"
553 loop_control:
554 label: "{{ item.item }}"
555
556 - name: Create quadlet image file - same
557 containers.podman.podman_image:
558 executable: "{{ test_executable | default('podman') }}"
559 name: quay.io/coreos/coreos-installer:latest
560 state: quadlet
561 arch: x86_64
562 ca_cert_dir: /etc/docker/certs.d
563 username: user
564 password: pass
565 validate_certs: false
566 quadlet_dir: /tmp
567 quadlet_options:
568 - "ImageTag=quay.io/coreos/coreos-installer:12345"
569 - "AllTags=true"
570 - |-
571 [Install]
572 WantedBy=default.target
573 register: quad2
574
575 - name: Check if quadlet changed
576 assert:
577 that:
578 - quad2 is not changed
579
580 - name: Create quadlet image file - different
581 containers.podman.podman_image:
582 executable: "{{ test_executable | default('podman') }}"
583 name: quay.io/coreos/coreos-installer:latest
584 state: quadlet
585 arch: arm64
586 ca_cert_dir: /etc/docker/certs.d
587 username: user
588 password: pass
589 validate_certs: false
590 quadlet_dir: /tmp/
591 quadlet_options:
592 - "ImageTag=quay.io/coreos/coreos-installer:12345"
593 - "AllTags=true"
594 - |-
595 [Install]
596 WantedBy=default.target
597 register: quad3
598
599 - name: Print diff
600 debug:
601 var: quad3.diff
602
603 - name: Check if changed and diff
604 assert:
605 that:
606 - quad3 is changed
607 - "'arm64' in quad3.diff.after"
608
609 - include_tasks: additional_tests.yml
610
611 - include_tasks: test_issue_947.yml
612 - include_tasks: test_issue_981.yml
613
614 always:
615 - name: Cleanup images
616 containers.podman.podman_image:
617 executable: "{{ test_executable | default('podman') }}"
618 name: "{{ item }}"
619 state: absent
620 loop:
621 - docker.io/library/ubuntu
622 - docker.io/library/alpine
623 - quay.io/sshnaidm1/alpine-sh
624 - quay.io/coreos/etcd:v3.3.11
625 - quay.io/coreos/etcd:v3.5.19
626 - quay.io/coreos/etcd:v3.5.27
627 - localhost/testimage
628 - localhost/testimage2
629 - localhost/testimage2:testtag
630 - localhost/testimage3
631 - localhost/dockerimage
632 - quay.io/testing/testimage
633 - quay.io/testing/testimage:draft
634 - testimage2:customfile
635 - testimage2:customfile2
636 - testimage2:failme
637 - testimage5x