Interview Prep/Ansible/Modules, Idempotency and Handlers

`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.

All Ansible questions Roadmap: Ansible

More on Modules, Idempotency and Handlers