Interview Prep/Ansible/Playbook Design, Handlers and Idempotency

You need to wait for an application to listen on port 8080 after a restart before continuing.

BeginnerScenarioPlaybook Design, Handlers and Idempotency
Answer

Situation read → Races between restart and the next step.

What I'd do →

- ansible.builtin.wait_for:
    port: 8080
    delay: 2
    timeout: 60
- ansible.builtin.uri:
    url: http://localhost:8080/health
    status_code: 200
  register: r
  retries: 10
  delay: 3
  until: r.status == 200

Why → Port open does not mean healthy; the uri retry loop proves the app answers.

Interview tip → wait_for can also wait for a file, a string in a file, or a port to drain.

All Ansible questions Roadmap: Ansible

More on Playbook Design, Handlers and Idempotency