| 1 |
- name: Test podman_container_info |
| 2 |
block: |
| 3 |
|
| 4 |
- name: Generate random value for container name |
| 5 |
set_fact: |
| 6 |
container_name: "{{ 'ansible-test-podman-%0x' % ((2**32) | random) }}" |
| 7 |
|
| 8 |
- name: Make sure container doesn't exist |
| 9 |
containers.podman.podman_container: |
| 10 |
executable: "{{ test_executable | default('podman') }}" |
| 11 |
name: "{{ container_name }}" |
| 12 |
state: absent |
| 13 |
|
| 14 |
- name: Get missing container info |
| 15 |
containers.podman.podman_container_info: |
| 16 |
executable: "{{ test_executable | default('podman') }}" |
| 17 |
name: "{{ container_name }}" |
| 18 |
register: nonexist |
| 19 |
|
| 20 |
- name: Check results of missing container info |
| 21 |
assert: |
| 22 |
that: |
| 23 |
- "'containers' in nonexist" |
| 24 |
- nonexist is succeeded |
| 25 |
- nonexist.containers == [] |
| 26 |
|
| 27 |
- name: Get missing multiple container info |
| 28 |
containers.podman.podman_container_info: |
| 29 |
executable: "{{ test_executable | default('podman') }}" |
| 30 |
name: |
| 31 |
- "{{ container_name }}" |
| 32 |
- neverexist |
| 33 |
- whatever |
| 34 |
register: nonexist2 |
| 35 |
ignore_errors: true |
| 36 |
|
| 37 |
- name: Check results of missing multiple container info |
| 38 |
assert: |
| 39 |
that: |
| 40 |
- "'containers' in nonexist2" |
| 41 |
- nonexist2 is succeeded |
| 42 |
- nonexist2.containers == [] |
| 43 |
|
| 44 |
- name: Make sure container exists |
| 45 |
command: podman container run -d --name {{ container_name }} alpine sleep 15m |
| 46 |
|
| 47 |
- name: Get existing container info |
| 48 |
containers.podman.podman_container_info: |
| 49 |
executable: "{{ test_executable | default('podman') }}" |
| 50 |
name: "{{ container_name }}" |
| 51 |
register: existing_container |
| 52 |
|
| 53 |
- name: Get mixed existing and non-existing container info |
| 54 |
containers.podman.podman_container_info: |
| 55 |
executable: "{{ test_executable | default('podman') }}" |
| 56 |
name: |
| 57 |
- "{{ container_name }}" |
| 58 |
- whatever |
| 59 |
register: mixed_existing_container |
| 60 |
|
| 61 |
- name: Get all containers info |
| 62 |
containers.podman.podman_container_info: |
| 63 |
executable: "{{ test_executable | default('podman') }}" |
| 64 |
register: all_containers |
| 65 |
|
| 66 |
- name: Dump podman container inspect result |
| 67 |
debug: var=existing_container |
| 68 |
|
| 69 |
- name: Comparison with 'podman container inspect' |
| 70 |
command: podman container inspect "{{ container_name }}" |
| 71 |
register: podman_inspect |
| 72 |
|
| 73 |
- name: Convert podman inspect output to JSON |
| 74 |
set_fact: |
| 75 |
podman_inspect_result: "{{ podman_inspect.stdout | from_json }}" |
| 76 |
|
| 77 |
- name: Cleanup |
| 78 |
containers.podman.podman_container: |
| 79 |
executable: "{{ test_executable | default('podman') }}" |
| 80 |
name: "{{ container_name }}" |
| 81 |
state: absent |
| 82 |
|
| 83 |
- name: Make checks |
| 84 |
# https://github.com/containers/podman/issues/9490 |
| 85 |
assert: |
| 86 |
that: |
| 87 |
- "'containers' in existing_container" |
| 88 |
- existing_container.containers | length > 0 |
| 89 |
# - "existing_container.containers == podman_inspect_result" |
| 90 |
# - all_containers.containers == existing_container.containers |
| 91 |
- "'containers' in mixed_existing_container" |
| 92 |
- mixed_existing_container.containers | length > 0 |
| 93 |
# - existing_container.containers == mixed_existing_container.containers |
| 94 |
|
| 95 |
always: |
| 96 |
|
| 97 |
- name: Cleanup |
| 98 |
containers.podman.podman_container: |
| 99 |
executable: "{{ test_executable | default('podman') }}" |
| 100 |
name: "{{ container_name }}" |
| 101 |
state: absent |