From cbb561ef3abf98f1aefb58b340bd22ac858c44e5 Mon Sep 17 00:00:00 2001 From: Emma Foley Date: Wed, 12 Feb 2025 16:41:52 +0000 Subject: [PATCH] [common] Update container tests Add an additional fail condition and make the fail_msg more verbose Update the container tests to use elevated permissions --- roles/common/tasks/container_test.yml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/roles/common/tasks/container_test.yml b/roles/common/tasks/container_test.yml index 2ccfa050..cdd8a55d 100644 --- a/roles/common/tasks/container_test.yml +++ b/roles/common/tasks/container_test.yml @@ -1,16 +1,24 @@ --- + # The containers are run by root, so need to become true - name: Get container status + become: true ansible.builtin.shell: cmd: | podman ps -a --format "{{ '{{.Names}} {{.Status}}' }}" | grep {{ container_name }} changed_when: false register: container_status + # NOTE: leaving the existing fail message to get the status and see if it is okay - name: | TEST Verify {{ container_name }} container status {{ common_container_test_id }} ansible.builtin.assert: that: + - "container_status.stdout | length != 0" - "'unhealthy' not in container_status.stdout" success_msg: "Container '{{ container_name }}' is in 'healthy' status." - fail_msg: "Container '{{ container_name }}' is not in 'healthy' status. Current status: {{ container_status.stdout }}" + fail_msg: | + Container does not meet the required conditions: + {%- if container_status.stdout | length == 0 %}Container name did not match any existing containers;{% endif %} + {%- if "unhealthy" in container_status.stdout %}Container status is unhealthy;{% endif %} + Container '{{ container_name }}' is not in 'healthy' status. Current status: {{ container_status.stdout }}