| 1 |
- name: A postgres container must exist, stopped |
| 2 |
containers.podman.podman_container: |
| 3 |
executable: "{{ test_executable | default('podman') }}" |
| 4 |
name: postgres_local |
| 5 |
image: docker.io/library/postgres:latest |
| 6 |
# image: quay.io/enterprisedb/postgresql - use if docker is rate limited |
| 7 |
state: stopped |
| 8 |
|
| 9 |
- name: Generate the systemd units as Ansible variables |
| 10 |
containers.podman.podman_generate_systemd: |
| 11 |
executable: "{{ test_executable | default('podman') }}" |
| 12 |
name: postgres_local |
| 13 |
register: postgres_local_systemd_unit |
| 14 |
ignore_errors: true |
| 15 |
|
| 16 |
- name: Check systemd unit are generated |
| 17 |
assert: |
| 18 |
that: |
| 19 |
- postgres_local_systemd_unit is succeeded |
| 20 |
|
| 21 |
- name: Check systemd unit exist in registered vars |
| 22 |
assert: |
| 23 |
that: |
| 24 |
- item.key == "container-postgres_local" |
| 25 |
- item.value != None |
| 26 |
loop: "{{ postgres_local_systemd_unit.systemd_units | dict2items }}" |
| 27 |
|
| 28 |
- name: Check podman command used to generate systemd units is returned |
| 29 |
assert: |
| 30 |
that: |
| 31 |
- postgres_local_systemd_unit.podman_command != "" |
| 32 |
|
| 33 |
- name: Regenerate the systemd units and write them |
| 34 |
containers.podman.podman_generate_systemd: |
| 35 |
executable: "{{ test_executable | default('podman') }}" |
| 36 |
name: postgres_local |
| 37 |
dest: /tmp/podman_generate_systemd |
| 38 |
register: postgres_local_systemd_unit |
| 39 |
ignore_errors: true |
| 40 |
|
| 41 |
- name: Check the unit files exists |
| 42 |
ansible.builtin.stat: |
| 43 |
path: "/tmp/podman_generate_systemd/{{ item.key }}.service" |
| 44 |
loop: "{{ postgres_local_systemd_unit.systemd_units | dict2items }}" |
| 45 |
|
| 46 |
- name: Try to create a systemd unit file on the same path |
| 47 |
containers.podman.podman_generate_systemd: |
| 48 |
executable: "{{ test_executable | default('podman') }}" |
| 49 |
name: postgres_local |
| 50 |
dest: /tmp/podman_generate_systemd |
| 51 |
register: generate1 |
| 52 |
|
| 53 |
- name: Check the unit files exists |
| 54 |
ansible.builtin.stat: |
| 55 |
path: "/tmp/podman_generate_systemd/{{ item.key }}.service" |
| 56 |
loop: "{{ generate1.systemd_units | dict2items }}" |
| 57 |
register: unitfile1 |
| 58 |
|
| 59 |
- name: Get checksum value |
| 60 |
set_fact: |
| 61 |
checksum1: "{{ item.stat.checksum }}" |
| 62 |
with_items: "{{ unitfile1.results }}" |
| 63 |
|
| 64 |
- name: Force to create a systemd unit file on the same path |
| 65 |
containers.podman.podman_generate_systemd: |
| 66 |
executable: "{{ test_executable | default('podman') }}" |
| 67 |
name: postgres_local |
| 68 |
dest: /tmp/podman_generate_systemd |
| 69 |
force: true |
| 70 |
register: generate2 |
| 71 |
|
| 72 |
- name: Check the unit files exists again |
| 73 |
ansible.builtin.stat: |
| 74 |
path: "/tmp/podman_generate_systemd/{{ item.key }}.service" |
| 75 |
loop: "{{ generate2.systemd_units | dict2items }}" |
| 76 |
register: unitfile2 |
| 77 |
|
| 78 |
- name: Get checksum value again |
| 79 |
set_fact: |
| 80 |
checksum2: "{{ item.stat.checksum }}" |
| 81 |
with_items: "{{ unitfile2.results }}" |
| 82 |
|
| 83 |
- name: Check if the systemd unit files are as expected |
| 84 |
assert: |
| 85 |
that: |
| 86 |
- generate1 is not changed |
| 87 |
- generate2 is changed |
| 88 |
- checksum1 != checksum2 |
| 89 |
|
| 90 |
- name: Regenerate the systemd units with all the options |
| 91 |
containers.podman.podman_generate_systemd: |
| 92 |
executable: "{{ test_executable | default('podman') }}" |
| 93 |
name: postgres_local |
| 94 |
new: true |
| 95 |
restart_policy: on-abnormal |
| 96 |
restart_sec: 19 |
| 97 |
start_timeout: 21 |
| 98 |
stop_timeout: 23 |
| 99 |
env: |
| 100 |
POSTGRES_USER: my_app |
| 101 |
POSTGRES_PASSWORD: example |
| 102 |
use_names: true |
| 103 |
container_prefix: more |
| 104 |
pod_prefix: less |
| 105 |
separator: + |
| 106 |
no_header: true |
| 107 |
after: drink.service |
| 108 |
wants: water.service |
| 109 |
requires: ice.service |
| 110 |
register: postgres_local_systemd_unit |
| 111 |
ignore_errors: true |
| 112 |
|
| 113 |
- name: Check the correct podman command is build |
| 114 |
assert: |
| 115 |
that: |
| 116 |
- postgres_local_systemd_unit.podman_command is search("postgres_local") |
| 117 |
- postgres_local_systemd_unit.podman_command is search("--new") |
| 118 |
- postgres_local_systemd_unit.podman_command is search("--restart-policy=on-abnormal") |
| 119 |
- postgres_local_systemd_unit.podman_command is search("--restart-sec=19") |
| 120 |
- postgres_local_systemd_unit.podman_command is search("--start-timeout=21") |
| 121 |
- postgres_local_systemd_unit.podman_command is search("--stop-timeout=23") |
| 122 |
- postgres_local_systemd_unit.podman_command is search("-e='POSTGRES_USER=my_app'") |
| 123 |
- postgres_local_systemd_unit.podman_command is search("-e='POSTGRES_PASSWORD=example'") |
| 124 |
- postgres_local_systemd_unit.podman_command is search("--name") |
| 125 |
- postgres_local_systemd_unit.podman_command is search("--container-prefix=more") |
| 126 |
- postgres_local_systemd_unit.podman_command is search("--pod-prefix=less") |
| 127 |
- postgres_local_systemd_unit.podman_command is search("--separator=+") |
| 128 |
- postgres_local_systemd_unit.podman_command is search("--no-header") |
| 129 |
- postgres_local_systemd_unit.podman_command is search("--after=drink.service") |
| 130 |
- postgres_local_systemd_unit.podman_command is search("--wants=water.service") |
| 131 |
- postgres_local_systemd_unit.podman_command is search("--requires=ice.service") |
| 132 |
- postgres_local_systemd_unit.podman_command is search("podman") |
| 133 |
|
| 134 |
- name: Remove container |
| 135 |
containers.podman.podman_container: |
| 136 |
executable: "{{ test_executable | default('podman') }}" |
| 137 |
name: postgres_local |
| 138 |
state: absent |
| 139 |
|
| 140 |
- name: Remove the systemd unit files directory |
| 141 |
ansible.builtin.file: |
| 142 |
path: /tmp/podman_generate_systemd |
| 143 |
state: absent |