tripleo-ansible/tripleo_ansible/roles/tripleo_container_manage/tasks/podman/check_exit_code.yml

52 lines
2.0 KiB
YAML

---
# Copyright 2020 Red Hat, Inc.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
- name: "Wait for containers to be exited"
podman_container_info:
name: "{{ containers_with_exit_code }}"
register: podman_containers_infos
until: ( podman_containers_infos.containers | selectattr('State.Running', 'equalto', True) |list|length ) == 0
# Retry 30 times every 10 seconds so we wait 5 min in total
retries: 30
delay: 10
# We need to ignore the failures since later we print some debug.
# We can't use "rescue" here because the debug tasks use
# "podman_containers_infos".
failed_when: false
no_log: "{{ not tripleo_container_manage_debug }}"
- name: Create a list of containers which didn't exit
set_fact:
running_containers: >-
{{ podman_containers_infos.containers |
selectattr('State.Running', 'equalto', True) | map(attribute='Name') | list }}
- name: Create a list of containers with bad Exit Codes
set_fact:
broken_containers: >-
{{ podman_containers_infos.containers |
rejectattr('State.ExitCode', 'in', tripleo_container_manage_valid_exit_code) | map(attribute='Name') | list }}
- name: "Print running containers"
fail:
msg: "Container(s) which are still running after 5 min: {{ running_containers }}, check logs in /var/log/containers/stdouts/"
when: running_containers|length != 0
- name: "Print failing containers"
fail:
msg: "Container(s) with bad ExitCode: {{ broken_containers }}, check logs in /var/log/containers/stdouts/"
when: broken_containers|length != 0