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 →
- Use state-based modules everywhere (
state: present). - Guard commands with
creates:or astatcheck. - Write temp files to a path that is cleaned in
always. - Use
--start-at-taskor tags only for resuming, never as a requirement. - Prove it: run twice and require
changed=0in 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.
More on Playbook Design, Handlers and Idempotency
Your playbook reports `changed` on every run for a task that runs a shell command. How do you fix it?BeginnerNginx must reload only when its config file actually changes.BeginnerA task fails halfway and its handler never ran, but the config file was changed. The next run shows no change and the service never reloads.AdvancedYou need three tasks to notify one handler, and want it to run once. Is that automatic?BeginnerYou need to deploy a binary only if it is missing or its checksum differs.IntermediateHow do you safely edit one line in `/etc/ssh/sshd_config` and be sure SSH keeps working?Intermediate