Interview Prep/Ansible/Modules, Idempotency and Handlers

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

All Ansible questions Roadmap: Ansible

More on Modules, Idempotency and Handlers