`wait_for` fails with `Timeout when waiting for 127.0.0.1:8080` although the app is up
IntermediateTroubleshootingModules, Idempotency and Handlers
Answer
Likely causes → The application listens on another interface (only the private IP, or only ::1), on a different port, or takes longer to start than timeout allows. If the task has delegate_to: localhost, it checks the controller, not the host.
Diagnose → ss -lntp | grep 8080 on the host.
Fix →
- ansible.builtin.wait_for:
host: "{{ ansible_host }}"
port: 8080
timeout: 120
delegate_to: localhost # only if you mean "reachable from outside"
For HTTP applications, prefer uri with until/retries against a health endpoint.
Prevent → Make the bind address an explicit role variable, and check health rather than just whether a port is open.
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