Pcornel
Automation · Ansible

Idempotency

Cheat sheet · https://pcornel.dk/topic.php?topic=5414

Back to the Topic

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 test
  • ansible-playbook site.yml (twice) — changed=0 on second
  • ansible-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

BoundaryHealthy evidenceSuspicious evidence
Inputs / selectionCorrect inventory, hosts, variables/facts and content are explicitWrong scope, stale facts, hidden precedence or content-version drift
ExecutionConnection, privilege, module/task context and ordering match intentUnreachable, wrong execution host, privilege/plugin failure or misleading skip/change state
Result semanticsPer-host/item results are preserved and interpreted correctlyAggregate recap hides partial/skipped/handled failures
Target proofResource/workload read-back and rerun confirm convergenceGreen 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

Confirmation

Confirm action

Continue?