state: healthy for docker_container
SUMMARY
Currently it's only possible to use state absent, present, stopped and started for the docker_container module. I would like to propose adding state: healthy to have Ansible wait until the integrated HEALTHCHECK returns healthy (when defined in the Dockerfile).
ISSUE TYPE
- Feature Idea
COMPONENT NAME
community.docker.docker_container
ADDITIONAL INFORMATION
By implementing this feature, a playbook can halt execution until the docker_container healtcheck returns healthy. This prevents additional tasks to poll for the health manually.
- name: Create database container
docker_container:
name: "database"
image: "mysql:latest"
state: "healthy" # This will trigger Ansible to wait for the HEALTHCHECK statement to return healthy, and fail if unhealthy.
restart: true
detach: true
pull: "always"
restart_policy: always
published_ports:
- "{{ db_fixture_port }}:3306"
Another idea would be to (also) have a separate module which allows to wait for several contains at once to reach the healthy state. That would allow users to start several containers first with the docker_container module, and then wait until all of them are healthy afterwards. This is likely faster than waiting for each to be healthy before starting the next.
Your case can then also be split up into just two tasks (without any explicit polling).
Obviously that doesn't mean that a state=healthy (or something similar) doesn't make sense / shouldn't be implemented, I think it's just more flexible to also have a separate module for just waiting :)
I've implemented state=healthy in #921.