mirror of
https://github.com/ansible-collections/community.docker.git
synced 2026-03-22 06:15:21 +00:00
* Allow to wait for a container to become healthy. * Improve wording. Co-authored-by: Don Naro <dnaro@redhat.com> * Improve explanation. --------- Co-authored-by: Don Naro <dnaro@redhat.com>
65 lines
1.6 KiB
YAML
65 lines
1.6 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
|
|
set_fact:
|
|
cname: "{{ cname_prefix ~ '-hi' }}"
|
|
- name: Registering container name
|
|
set_fact:
|
|
cnames: "{{ cnames + [cname] }}"
|
|
|
|
- name: Prepare container
|
|
docker_container:
|
|
name: "{{ cname }}"
|
|
image: "{{ docker_test_image_healthcheck }}"
|
|
command: '10m'
|
|
state: stopped
|
|
register: healthy_1
|
|
|
|
- debug: var=healthy_1.container.State
|
|
|
|
- name: Start container (not healthy in time)
|
|
docker_container:
|
|
name: "{{ cname }}"
|
|
state: healthy
|
|
healthy_wait_timeout: 1
|
|
register: healthy_2
|
|
ignore_errors: true
|
|
|
|
- debug: var=healthy_2.container.State
|
|
|
|
- name: Prepare container
|
|
docker_container:
|
|
name: "{{ cname }}"
|
|
image: "{{ docker_test_image_healthcheck }}"
|
|
command: '10m 5s'
|
|
state: stopped
|
|
force_kill: true
|
|
register: healthy_3
|
|
|
|
- debug: var=healthy_3.container.State
|
|
|
|
- name: Start container (healthy in time)
|
|
docker_container:
|
|
name: "{{ cname }}"
|
|
state: healthy
|
|
healthy_wait_timeout: 10
|
|
register: healthy_4
|
|
|
|
- debug: var=healthy_4.container.State
|
|
|
|
- name: Cleanup
|
|
docker_container:
|
|
name: "{{ cname }}"
|
|
state: absent
|
|
force_kill: true
|
|
- 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"
|