community.docker/tests/integration/targets/docker_container/tasks/tests/healthy.yml
2025-10-25 10:12:21 +02:00

65 lines
1.8 KiB
YAML

---
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
- name: Registering container name
ansible.builtin.set_fact:
cname: "{{ cname_prefix ~ '-hi' }}"
- name: Registering container name
ansible.builtin.set_fact:
cnames: "{{ cnames + [cname] }}"
- name: Prepare container
community.docker.docker_container:
name: "{{ cname }}"
image: "{{ docker_test_image_healthcheck }}"
command: '10m'
state: stopped
register: healthy_1
- ansible.builtin.debug: var=healthy_1.container.State
- name: Start container (not healthy in time)
community.docker.docker_container:
name: "{{ cname }}"
state: healthy
healthy_wait_timeout: 1
register: healthy_2
ignore_errors: true
- ansible.builtin.debug: var=healthy_2.container.State
- name: Prepare container
community.docker.docker_container:
name: "{{ cname }}"
image: "{{ docker_test_image_healthcheck }}"
command: '10m 5s'
state: stopped
force_kill: true
register: healthy_3
- ansible.builtin.debug: var=healthy_3.container.State
- name: Start container (healthy in time)
community.docker.docker_container:
name: "{{ cname }}"
state: healthy
healthy_wait_timeout: 10
register: healthy_4
- ansible.builtin.debug: var=healthy_4.container.State
- name: Cleanup
community.docker.docker_container:
name: "{{ cname }}"
state: absent
force_kill: true
- ansible.builtin.assert:
that:
- healthy_2 is failed
- healthy_2.container.State.Health.Status == "starting"
- healthy_2.msg.startswith("Timeout of 1.0 seconds exceeded while waiting for container ")
- healthy_4 is changed
- healthy_4.container.State.Health.Status == "healthy"