module

Krikri::PluginHelpers::DockerHealthWait

DockerHealthWait - real community.docker's docker_container state=healthy wait loop, behavior matched to the Ansible module module.py's wait_for_state (as called for the healthy state with wait_states=['starting', 'unhealthy'], complete_states=['healthy', None], max_wait=healthy_wait_timeout, health_state=True) and its per-state failure wordings.

Behavior mirrored exactly (live-verified against ansible-playbook 2.19.11 + the local docker/podman daemon unless marked source-only):

  • polls the container's inspect output, reading State.Health.Status; None/missing (no healthcheck) is immediately healthy - Ansible's own "None means that no health check enabled; simply treat this as 'healthy'".
  • 'unhealthy' is a WAIT state, not an immediate failure: the loop keeps polling until the timeout expires (live-verified: real reports the timeout message, not an "unhealthy" message).
  • poll delay starts at 1s and grows exponentially (*1.1) capped at 10s (Ansible's own comment: 25 iterations to reach the cap).
  • timeout: fires when total_wait > max_wait or delay < 1e-4 (after clamping the last sleep to not overshoot max_wait) with Ansible's wording Timeout of <max_wait> seconds exceeded while waiting for container "<id>" (Float64 formatting, so healthy_wait_timeout: 8 renders as "8.0").
  • a vanished container (inspect 404) fails with Ansible's (sic) "Encontered vanished container while waiting for container "<id>"" - the typo is Ansible's own, mirrored verbatim.
  • any other health status fails with Ansible's "Encontered unexpected state "<status>" while waiting for container "<id>"" (in practice unreachable for real daemons, whose only health statuses are starting/healthy/unhealthy/none).
  • other inspect errors fail with Ansible's "Error inspecting container: <error>".

Both the inspect call and the sleep are injected so the loop is unit-testable without a daemon (sleep_fn in tests returns immediately; the plugin passes a real sleep).

Constants

COMPLETE_STATES = ["healthy", nil] of String | ::Nil
WAIT_STATES = ["starting", "unhealthy"] of String | ::Nil

Class methods

health_status(inspect_json : JSON::Any) : String | Nil

Ansible's state_info.get('Status') on State.Health - missing State, missing Health (no healthcheck) or missing Status all mean None (immediately healthy).

Source
wait_for_healthy(container_id : String, max_wait : Float64 | Nil, inspect_fn : InspectFn, sleep_fn : SleepFn) : JSON::Any
Source

Nested types