Idempotency
Cheat sheet · https://pcornel.dk/topic.php?topic=5414
Answer
Idempotent Ansible automation converges a resource toward desired state so repeating the same inputs against an already-converged target normally produces no additional change.
Remember
- Second run changed=0 ≠ full correctness; wrong desired state can be consistently idempotent.
- Repeated changed=true ≠ automatically module bug; volatile inputs, timestamps or external state can drive legitimate differences.
- Task-level idempotency ≠ workflow idempotency; handlers/external commands/APIs can still have side effects.
- Idempotent ≠ immutable; out-of-band drift can require later changes.
First checks
molecule test (idempotence step)— automatic testansible-playbook site.yml (twice)— changed=0 on secondansible-lint— flags non-idempotent patterns
Verify in this order
play → second run → changed=0
Where it usually breaks
A no-change rerun supports convergence/idempotency for the checked resources; it does not prove the desired state itself is correct or the application is healthy.
Inventory/vars → play/task selection → connection/become → module request → module result → target object read-back → handler/service effective state → workload verification.
Idempotency Ansible boundary map
| Boundary | Healthy evidence | Suspicious evidence |
|---|---|---|
| Inputs / selection | Correct inventory, hosts, variables/facts and content are explicit | Wrong scope, stale facts, hidden precedence or content-version drift |
| Execution | Connection, privilege, module/task context and ordering match intent | Unreachable, wrong execution host, privilege/plugin failure or misleading skip/change state |
| Result semantics | Per-host/item results are preserved and interpreted correctly | Aggregate recap hides partial/skipped/handled failures |
| Target proof | Resource/workload read-back and rerun confirm convergence | Green Ansible status treated as end-to-end acceptance |
Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=5414