DEVOPS / A CONCEPT NOTE

Idempotency

why running twice must be safe

~60 sec read

Overview · mechanism
pitfall · examples

01 / THE SHORT VERSION

The idea in a few sentences.

A property where executing an operation multiple times produces the exact same result as executing it once, preventing resource duplication or configuration errors.

02 / FOLLOW THE MECHANISM

How idempotent runs flow

  1. First execution

    playbook/script runs, detects resource missing, and creates it.

  2. Second execution

    runs, detects resource already exists, and reports ok (no changes).

  3. Failsafe check

    operations evaluate current state before modifying resource attributes.

  4. Result

    system stays in the desired configuration state without duplicating objects.

04 / COMMAND NOTES

Read the command, then the result.

Inspect the flags and arguments before trying an example. Snippets can need local setup, replacement values, or resources in your own environment.

EXAMPLE 01 · REFERENCE

verify if tasks will make changes without altering target state

ansible-playbook --check playbook.yml

EXAMPLE 02 · REFERENCE

idempotently create a directory (succeeds even if folder exists)

mkdir -p my-dir

Explore command anatomy in the CLI lab