Use this when making configuration management runs safe to repeat.
Idempotency · Configuration Management
Idempotency in configuration management means each resource or module only changes a system when it differs from the desired state, so runs can repeat without side effects and report 'ok' when nothing changed.
1. Idempotency: rerun changes nothing.
2. Guard command/shell with creates/changed_when.
3. Test with double runs (Molecule idempotence).
4. Avoid timestamps in templates.
5. Required for safe enforcement.
run → state matches → no changes on rerun
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 Verification path Verify boundary
The negative fixture should deliberately exercise risks such as ambiguous target identity, stale inputs, partial success, unsafe retry, permission drift and confusing tool completion with target-evidence of the actual state, choosing the cases most relevant to repeated execution against unchanged desired state should produce a no-op, while drift or changed intent produces the minimal required mutation.
Step 2 What it is Narrow the fault
Idempotency means running the same automation again changes nothing if the state is already correct; the second run should report changed=0.
Step 3 Common mistakes Narrow the fault
- Tasks that always report changed.
- Appending lines to files on every run.
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.
- Modules check before changing.
- 'ok' means no change.
- Shell commands need guards.
ansible-playbook site.yml; ansible-playbook site.yml— second run changed=0ansible-lint (no-changed-when)— command tasks flagged- changed_when/creates on commands — guarded
ReferenceWhy it matters1 section · depth on demand
Internals and state
Idempotency means repeated execution converges without unintended change; it does not by itself show the desired state is correct or useful.
ReferenceImportant terms & boundaries2 sections · depth on demand
In depth
Idempotency in configuration management means applying the same configuration again changes nothing when the system is already correct. It is what makes configuration management safe to run on a schedule to correct drift.
How tools achieve it: each resource compares current state with desired state and changes only differences. It breaks when playbooks use raw commands, append to files, or generate content that differs each run (timestamps, random ordering).
# Not idempotent
- ansible.builtin.shell: echo "server 10.0.0.123" >> /etc/chrony.conf
# Idempotent
- ansible.builtin.lineinfile:
path: /etc/chrony.conf
line: "server 10.0.0.123 iburst"
Test: run twice; the second run must report no changes.
Example
ansible-playbook site.yml # run twice; second run: changed=0
terraform plan # "No changes" after apply
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 Configuration Management > Idempotency. Documentation verification only; this is not observed lab or production Evidence.
Basis: https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_intro.html · confidence 94%Deep reference
Healthy vs suspicious evidence
Output interpretation
For repeated execution against unchanged desired state should produce a no-op, while drift or changed intent produces the minimal required mutation, prefer typed fields and stable IDs over human presentation text.