diff --git a/tripleo_ansible/roles/tripleo-container-manage/tasks/container_running.yml b/tripleo_ansible/roles/tripleo-container-manage/tasks/container_running.yml index 7d51b5056..17cee9849 100644 --- a/tripleo_ansible/roles/tripleo-container-manage/tasks/container_running.yml +++ b/tripleo_ansible/roles/tripleo-container-manage/tasks/container_running.yml @@ -14,16 +14,12 @@ # License for the specific language governing permissions and limitations # under the License. # -- name: "Get {{ lookup('dict', container_exists_data).value.command.0 }} container status" - set_fact: - container_running: >- - {{ podman_containers.containers | selectattr('Name', 'equalto', lookup('dict', container_exists_data).value.command.0) | - map(attribute='State.Running') | first | default(false) }} - -- name: "Fail if {{ lookup('dict', container_exists_data).value.command.0 }} is not running" - fail: - msg: >- +- name: "Assert that {{ lookup('dict', container_exists_data).value.command.0 }} is running before exec" + assert: + that: + - podman_containers.containers | selectattr('Name', 'equalto', lookup('dict', container_exists_data).value.command.0) | + map(attribute='State.Running') | first | default(false) + fail_msg: >- Can't run container exec for {{ lookup('dict', container_exists_data).key }}, {{ lookup('dict', container_exists_data).value.command.0 }} is not running - when: - - not container_running|default(false)|bool + success_msg: "{{ lookup('dict', container_exists_data).value.command.0 }} is running" diff --git a/tripleo_ansible/roles/tripleo-container-manage/tasks/create.yml b/tripleo_ansible/roles/tripleo-container-manage/tasks/create.yml index 389d457d8..afc4d4c0a 100644 --- a/tripleo_ansible/roles/tripleo-container-manage/tasks/create.yml +++ b/tripleo_ansible/roles/tripleo-container-manage/tasks/create.yml @@ -22,5 +22,9 @@ - name: "Manage container systemd services and healthchecks for {{ tripleo_container_manage_config }}" include_tasks: podman/systemd.yml + vars: + container_config: "{{ all_containers_hash | dict_to_list | haskey(attribute='restart', value=['always','unless-stopped'], any=True) | default([]) }}" + container_config_healthcheck: "{{ all_containers_hash | dict_to_list | haskey(attribute='healthcheck') | intersect(container_config) | default([]) }}" when: - tripleo_container_manage_cli == 'podman' + - (container_config|length) > 0 diff --git a/tripleo_ansible/roles/tripleo-container-manage/tasks/podman/check_exit_code.yml b/tripleo_ansible/roles/tripleo-container-manage/tasks/podman/check_exit_code.yml new file mode 100644 index 000000000..456a71ab2 --- /dev/null +++ b/tripleo_ansible/roles/tripleo-container-manage/tasks/podman/check_exit_code.yml @@ -0,0 +1,51 @@ +--- +# 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 exit" + podman_container_info: + name: "{{ batched_container_data | haskey(attribute='action', reverse=True) | list_of_keys }}" + 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 diff --git a/tripleo_ansible/roles/tripleo-container-manage/tasks/podman/create.yml b/tripleo_ansible/roles/tripleo-container-manage/tasks/podman/create.yml index 40dd3abf5..7f65c7b71 100644 --- a/tripleo_ansible/roles/tripleo-container-manage/tasks/podman/create.yml +++ b/tripleo_ansible/roles/tripleo-container-manage/tasks/podman/create.yml @@ -117,35 +117,4 @@ when: - tripleo_container_manage_valid_exit_code|length != 0 - not ansible_check_mode|bool - block: - - name: "Wait for containers to be exited" - podman_container_info: - name: "{{ batched_container_data | haskey(attribute='action', reverse=True) | list_of_keys }}" - 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/stdout/" - when: running_containers|length != 0 - - name: "Print failing containers" - fail: - msg: "Container(s) with bad ExitCode: {{ broken_containers }}, check logs in /var/log/containers/stdout/" - when: broken_containers|length != 0 + include_tasks: podman/check_exit_code.yml diff --git a/tripleo_ansible/roles/tripleo-container-manage/tasks/podman/systemd.yml b/tripleo_ansible/roles/tripleo-container-manage/tasks/podman/systemd.yml index 9ccffe240..0f3a8da24 100644 --- a/tripleo_ansible/roles/tripleo-container-manage/tasks/podman/systemd.yml +++ b/tripleo_ansible/roles/tripleo-container-manage/tasks/podman/systemd.yml @@ -14,17 +14,6 @@ # License for the specific language governing permissions and limitations # under the License. -- name: Set container_config fact - set_fact: - container_config: "{{ all_containers_hash | dict_to_list | haskey(attribute='restart', value=['always','unless-stopped'], any=True) | default([]) }}" - -- name: Set container_config_healthcheck fact - set_fact: - # Using intersect to prevent a service which isn't controlled by systemd - # but has healthcheck in its configuration (by mistake) - # See https://bugs.launchpad.net/tripleo/+bug/1873249 - container_config_healthcheck: "{{ all_containers_hash | dict_to_list | haskey(attribute='healthcheck') | intersect(container_config) | default([]) }}" - - name: "Manage systemd files" no_log: "{{ not tripleo_container_manage_debug }}" block: