Interview Prep/Ansible/Playbook Design, Handlers and Idempotency

You must ensure a playbook can be re-run after any failure without cleaning up manually.

AdvancedScenarioPlaybook Design, Handlers and Idempotency
Answer

Situation read → Idempotent and restartable design.

What I'd do →

  1. Use state-based modules everywhere (state: present).
  2. Guard commands with creates: or a stat check.
  3. Write temp files to a path that is cleaned in always.
  4. Use --start-at-task or tags only for resuming, never as a requirement.
  5. Prove it: run twice and require changed=0 in CI.

Why → If a half-applied state breaks re-runs, the playbook encodes steps rather than a desired state.

Interview tip → "Run it twice" is the single best idempotency test.

All Ansible questions Roadmap: Ansible

More on Playbook Design, Handlers and Idempotency