Debian Codegraph @

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

raw
1 - name: Test podman_container_exec
2 block:
3 - name: Generate random value for container name
4 set_fact:
5 container_name: "{{ 'ansible-test-podman-%0x' % ((2**32) | random) }}"
6
7 - name: Make sure container doesn't exist
8 containers.podman.podman_container:
9 executable: "{{ test_executable | default('podman') }}"
10 name: "{{ container_name }}"
11 state: absent
12
13 - name: Test exec when the container doesn't exist
14 containers.podman.podman_container_exec:
15 executable: "{{ test_executable | default('podman') }}"
16 name: "{{ container_name }}"
17 command: "cat /etc/redhat-release"
18 ignore_errors: true
19 register: no_container
20
21 - name: Create and start a container for testing
22 containers.podman.podman_container:
23 executable: "{{ test_executable | default('podman') }}"
24 name: "{{ container_name }}"
25 image: registry.access.redhat.com/ubi8
26 command: sleep 1d
27 state: started
28
29 - name: Test exec with command and workdir options
30 containers.podman.podman_container_exec:
31 executable: "{{ test_executable | default('podman') }}"
32 name: "{{ container_name }}"
33 command: "cat redhat-release"
34 workdir: /etc
35 register: exec1
36
37 - name: Test exec with argv and env options
38 containers.podman.podman_container_exec:
39 executable: "{{ test_executable | default('podman') }}"
40 name: "{{ container_name }}"
41 argv:
42 - /bin/sh
43 - -c
44 - echo $HELLO $BYE
45 env:
46 HELLO: hello world
47 BYE: goodbye world
48 register: exec2
49
50 - name: Test exec with detach option
51 containers.podman.podman_container_exec:
52 executable: "{{ test_executable | default('podman') }}"
53 name: "{{ container_name }}"
54 command: "cat redhat-release"
55 detach: true
56 register: exec3
57
58 - name: Check if the result is as expected
59 assert:
60 that:
61 - no_container is failed
62 - "'Red Hat Enterprise Linux' in exec1.stdout"
63 - "'hello world' in exec2.stdout"
64 - "'goodbye world' in exec2.stdout"
65 - exec3.exec_id is defined
66
67 - name: Test exec with failing command
68 containers.podman.podman_container_exec:
69 executable: "{{ test_executable | default('podman') }}"
70 name: "{{ container_name }}"
71 command: "ls /nonexistent"
72 register: exec4
73 ignore_errors: true
74
75 - name: Check if the result is as expected in case of a failing command
76 assert:
77 that:
78 - exec4 is failed
79 - "'No such file or directory' in exec4.stderr"
80 - exec4.rc != 0
81
82 always:
83 - name: Cleanup
84 containers.podman.podman_container:
85 executable: "{{ test_executable | default('podman') }}"
86 name: "{{ container_name }}"
87 state: absent