`FAILED - RETRYING: [web01]: Wait for app health (5 retries left).` ends in failure although the app is healthy
IntermediateTroubleshootingModules, Idempotency and Handlers
Answer
Likely causes → The until condition is wrong: it checks a key that does not exist, compares a string with an integer, or the task is missing register. Another cause is that uri itself fails on a non-200 code and never gets to evaluate until the way you expect.
Fix →
- ansible.builtin.uri:
url: "http://{{ ansible_host }}:8080/health"
status_code: [200, 503]
return_content: true
register: health
until: health.status == 200 and (health.json.status | default('')) == 'UP'
retries: 20
delay: 6
Prevent → Run the task once with -vvv and copy the exact result keys into your condition.
More on Modules, Idempotency and Handlers
`ERROR! The requested handler 'Restart nginx' was not found in either the main handlers list nor in the listening handlers list`BeginnerA handler named `restart {{ app_service }}` is never found when notified as `restart myapp`AdvancedA `command` task reports `changed` on every run, and the Molecule idempotence check failsBeginner`curl ... | tar xz` fails on the host but the `shell` task reports successIntermediate`lineinfile` appends the same line again on every runIntermediate`lineinfile` with `backrefs: true` reports `ok` but the line was never addedIntermediate