Use it when configuring, checking or troubleshooting Idempotency in Ansible.
Idempotency · Ansible
Idempotent Ansible automation converges a resource toward desired state so repeating the same inputs against an already-converged target normally produces no additional change.
1. Idempotency in Ansible: use modules, guard commands, avoid always-changing templates.
2. Molecule's idempotence step.
3. changed_when for commands.
4. No random/timestamp content.
5. Required for enforcement runs.
play → second run → changed=0
Context & applicabilityCommon mistakes · platform/version boundaries
Operational reference
Fast context before you go deeper.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
Capture the concrete output, symptom, packet, log or counter before changing anything.
Step 1 Operational evidence path Verify boundary
stable intent/inputs → first convergence → target read-back → identical rerun → changed-task diff → acceptance verification
Healthy evidence: stable inputs produce intended target state and a repeated run shows no unexplained changes while application checks remain healthy.
Step 2 Failure modes and next checks Narrow the fault
Suspicious evidence: timestamps/random values, command/shell side effects, unstable ordering, external drift or using changed=0 as the only correctness criterion.
Step 3 Common mistakes Narrow the fault
commandtasks withoutcreates/changed_when.
Step 4 Where it fails Narrow the fault
Where Idempotency usually goes wrong: stable operation key, desired/current-state comparison, no-op behavior and duplicate-mutation prevention.
Evidence · 1 on this Topic
Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.
- 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.
molecule test (idempotence step)— automatic testansible-playbook site.yml (twice)— changed=0 on secondansible-lint— flags non-idempotent patterns
ReferenceWhat it is1 section · depth on demand
Core model
Measure idempotency with stable inputs and target state: first converge, read back state, rerun unchanged content and investigate any repeated change at the first module/resource boundary.
ReferenceImportant terms & boundaries2 sections · depth on demand
What this shows and what it does not
A no-change rerun supports convergence/idempotency for the checked resources, but it does not show the desired state itself is correct or the application is healthy.
In depth
In Ansible, idempotency means a playbook can be run repeatedly and only reports changes when something actually differed. Built-in modules check state before acting; command and shell do not, so they need help.
- name: Initialise app (only once)
ansible.builtin.command: /opt/app/init.sh
args:
creates: /opt/app/.initialised
- name: Read status (never a change)
ansible.builtin.command: systemctl is-active app
register: st
changed_when: false
Test by running the playbook twice; the second run should show changed=0 in the recap.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Verification history & basis
When and against what this Topic was checked. Later text edits do not count as a new check.
Authoritative/upstream documentation reviewed for bounded claims in Ansible > Idempotency. Documentation verification only; this is not observed lab or production Evidence.
Basis: https://docs.ansible.com/ansible/latest/ · confidence 94%Terms & aliases
Hover a linked term for a quick definition; click it to open its glossary entry. Aliases are other names that find this Topic in search.
Quick lookup tables
Idempotency Ansible boundary map
Fast input/selection, execution/result and target-proof boundaries for Idempotency.
| 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 |
Deep reference
Healthy vs suspicious evidence
Output interpretation
For Idempotency, rely on structured fields and stable IDs (stable operation key, desired/current-state comparison, no-op behavior and duplicate-mutation prevention) rather than text formatted for display.