Pcornel
Browse topics
Options
Recent
Favorites
Automation · Technical reference

Idempotency · Ansible

Direct 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.

When to use this

Use it when configuring, checking or troubleshooting Idempotency in Ansible.

First 30 seconds

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.

Operational verification

play → second run → changed=0

Context & applicabilityCommon mistakes · platform/version boundaries
Platform / version applicability
Ansible automation
applies
Structured applicability is explicit Topic metadata; it does not infer compatibility beyond the stored rows.
At a glance

Operational reference

Fast context before you go deeper.

PlatformAnsible automation · Idempotency owns Ansible convergence behavior. Automation Fundamentals owns the broader general concept; target acceptance stays with the target domain.
Scope / prerequisiteUse it when configuring, checking or troubleshooting Idempotency in Ansible.
What next?3 suggested next steps
Evidence1
On this pageJump to a specific section
Operational workflow

Verification & Troubleshooting

Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.

4 steps Observe → verify → isolate → change minimally → repeat the original test.
ObservedRecord what the original test actually shows

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
  • command tasks without creates/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 references

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.

observation · 1
Key points
  • 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.
Key checks
  • molecule test (idempotence step) — automatic test
  • ansible-playbook site.yml (twice) — changed=0 on second
  • ansible-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.

Source basisSource attribution states what this section is based on; it is not independent proof that the current environment matches it.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Technical verification history

Verification history & basis

When and against what this Topic was checked. Later text edits do not count as a new check.

2026-09-14 · vendor docAnsible automation current

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%
Terminology layer

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.

Aliases that resolve here
ansible idempotencyidempotent playbooksecond run no changesconfiguration convergence
Embedded reference data

Quick lookup tables

Idempotency Ansible boundary map

Fast input/selection, execution/result and target-proof boundaries for Idempotency.

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
Depth when you need it

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.

Confirmation

Confirm action

Continue?