Pcornel
Browse topics
Options
Recent
Favorites
Automation · Technical reference

Create-if-Missing

Direct answer

Create-if-missing is an idempotent pattern: check whether a resource exists and create it only if it does not, such as a user, folder or VLAN, so reruns do not create duplicates or fail.

When to use this

Use this when a resource should be created only if missing.

First 30 seconds

1. Create-if-missing: look up by unique key; create only if absent.

2. Treat 'already exists' as success.

3. Race conditions — use atomic APIs if available.

4. Log decisions.

5. Test reruns.

Operational verification

lookup → missing? create : no-op

Context & applicabilityCommon mistakes · platform/version boundaries
Platform / version applicability
idempotent configuration 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.

Platformidempotent configuration automation · Automation implementations are tool and platform specific. Use the adjacent Domain for the technology being automated and this Domain for automation behavior.
Scope / prerequisiteUse this when a resource should be created only if missing.
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.

2 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 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 existence/read-before-create checks, stable lookup keys, race-safe creation and no-op behavior when the object already exists.

Step 2 Common mistakes Narrow the fault
  • Check-then-create races in parallel runs.
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
  • Look up the resource before creating it.
  • Use a unique key for the lookup.
  • Report whether it was created or already existed.
Key checks
  • Check existence before create — guard
  • Unique keys for lookup — identification
  • Handle 409/already exists as success — idempotency
ReferenceWhy it matters1 section · depth on demand

What it is

Create-if-missing checks whether an object exists before creating it.

ReferenceImportant terms & boundaries1 section · depth on demand

In depth

Create-if-missing is the simplest idempotent pattern: check whether an object exists, and create it only if it does not. Running it again finds the object and does nothing. It does not correct an object that exists with wrong settings — that requires update-if-different.

r = requests.get(f"{api}/vlans/?vid=20", headers=h)
if r.json()["count"] == 0:
    requests.post(f"{api}/vlans/", headers=h, json={"vid": 20, "name": "USERS"})
id -u svc_backup >/dev/null 2>&1 || useradd --system svc_backup
mkdir -p /opt/app      # -p: no error if it exists
if (-not (Get-ADGroup -Filter "Name -eq 'SG-Backup'")) { New-ADGroup SG-Backup -GroupScope Global }

Race condition warning: two parallel runs can both see "missing" and both create. Use unique constraints or locks where duplicates would cause harm.

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 docidempotent configuration automation current

Authoritative/upstream documentation reviewed for bounded claims in Idempotency > Create-if-Missing. 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%
Depth when you need it

Deep reference

Healthy vs suspicious evidence

Output interpretation

For existence/read-before-create checks, stable lookup keys, race-safe creation and no-op behavior when the object already exists, prefer typed fields and stable IDs over human presentation text.

Confirmation

Confirm action

Continue?