poll docker compose ps for running+healthy state
This commit is contained in:
@@ -1,14 +1,4 @@
|
|||||||
---
|
---
|
||||||
- name: Wait for container to be healthy
|
|
||||||
community.docker.docker_container_info:
|
|
||||||
name: "{{ app_container_name }}"
|
|
||||||
register: container_info
|
|
||||||
until: container_info.container.State.Health.Status | default('healthy') == 'healthy'
|
|
||||||
retries: "{{ app_health_check_retries | default(30) }}"
|
|
||||||
delay: "{{ app_health_check_delay | default(10) }}"
|
|
||||||
when: app_health_check | default(true) and app_health_check_method | default('docker') == 'docker'
|
|
||||||
ignore_errors: true
|
|
||||||
|
|
||||||
- name: Verify application HTTP endpoint
|
- name: Verify application HTTP endpoint
|
||||||
ansible.builtin.uri:
|
ansible.builtin.uri:
|
||||||
url: "{{ app_health_check_url }}"
|
url: "{{ app_health_check_url }}"
|
||||||
@@ -19,25 +9,19 @@
|
|||||||
retries: "{{ app_health_check_retries | default(30) }}"
|
retries: "{{ app_health_check_retries | default(30) }}"
|
||||||
delay: "{{ app_health_check_delay | default(10) }}"
|
delay: "{{ app_health_check_delay | default(10) }}"
|
||||||
when: app_health_check | default(true) and app_health_check_method | default('docker') == 'http' and app_health_check_url is defined
|
when: app_health_check | default(true) and app_health_check_method | default('docker') == 'http' and app_health_check_url is defined
|
||||||
ignore_errors: true
|
|
||||||
|
|
||||||
- name: Inspect compose project containers
|
- name: Wait for compose services to be running (and healthy if applicable)
|
||||||
community.docker.docker_host_info:
|
ansible.builtin.command:
|
||||||
containers: true
|
cmd: docker compose ps --all --format json
|
||||||
containers_all: true
|
chdir: "{{ app_dir }}"
|
||||||
containers_filters:
|
register: _compose_ps
|
||||||
label: "com.docker.compose.project={{ app_compose_project_name }}"
|
changed_when: false
|
||||||
register: compose_containers
|
retries: "{{ app_health_check_retries | default(30) }}"
|
||||||
when: app_health_check | default(true)
|
delay: "{{ app_health_check_delay | default(10) }}"
|
||||||
|
|
||||||
- name: Verify deployment success
|
|
||||||
vars:
|
vars:
|
||||||
_total: "{{ compose_containers.containers | length }}"
|
_services: "{{ _compose_ps.stdout_lines | map('from_json') | list }}"
|
||||||
_running: "{{ compose_containers.containers | selectattr('State', 'equalto', 'running') | list | length }}"
|
until:
|
||||||
ansible.builtin.assert:
|
- _services | length > 0
|
||||||
that:
|
- _services | rejectattr('State', 'equalto', 'running') | list | length == 0
|
||||||
- compose_containers.containers | length > 0
|
- _services | selectattr('Health', 'defined') | selectattr('Health', 'in', ['unhealthy', 'starting']) | list | length == 0
|
||||||
- _running == _total
|
when: app_health_check | default(true) and app_health_check_method | default('docker') == 'docker'
|
||||||
fail_msg: "Not all containers are running. Running: {{ _running }}, Total: {{ _total }}"
|
|
||||||
success_msg: "All containers are running successfully."
|
|
||||||
when: app_health_check | default(true) and compose_containers.containers is defined
|
|
||||||
|
|||||||
Reference in New Issue
Block a user