DevOps Bootcamp · Lesson

allow_duplicates & Role Idempotency

Control repeated role execution.

Lesson 4 of 413 steps

allow_duplicates & Role Idempotency is a free DevOps Bootcamp lesson on CoddyKit. This is lesson 4 of 4. Any 3 lessons of this learning path are free to read in full — after that, CoddyKit PRO unlocks every lesson, plus hands-on practice with a built-in code editor and a 24/7 AI tutor. It is part of the DevOps Bootcamp learning path, and your progress syncs across the web and the CoddyKit app. The DevOps Bootcamp course includes 4 lessons in total.

Roles Run Once by Default

If two roles both depend on a common role, Ansible is smart: it runs common only once, not twice, during a single play.

Why Dedup Exists

This deduplication stops shared setup roles from repeating expensive work, like re-running a base hardening role for every app role.

Same Role, Same Params

The skip only applies when the role is requested with the same parameters. Identical calls are treated as already done.

Different Params, Runs Again

Call the same role with different variables and Ansible runs it again. A vhost role with two configs applies twice, as you want.

roles:
  - role: vhost
    vars: { name: site_a }
  - role: vhost
    vars: { name: site_b }

Meet allow_duplicates

The allow_duplicates setting in meta/main.yml controls this behavior. Set it to true and the role may run repeatedly within a play.

# meta/main.yml
allow_duplicates: true

When to Allow Duplicates

Turn it on for roles meant to apply many times, like creating multiple users or virtual hosts, each call doing genuinely new work.

Default Is False

By default allow_duplicates is false, so a role with identical params runs just once. Leave it off for one-time setup roles.

Dedup Is Not Idempotency

Skipping a duplicate call is a runtime convenience. True idempotency is each task converging to a state, no matter how often it runs.

Build Idempotent Tasks

Inside a role, prefer state-based modules over raw command. A role that is truly idempotent is safe to apply twice with no harm.

include_role Always Re-runs

Watch out: include_role does not honor the dedup logic the same way. A dynamically included role runs each time you reach it.

Composable and Safe

Combine dedup, allow_duplicates, and idempotent tasks to build role hierarchies that compose cleanly and stay safe to re-run.

Quick Check

Recall the setting that lets a role run more than once in a play.

Recap

Ansible dedups identical role calls; set allow_duplicates to true to repeat one, and keep tasks idempotent for safe re-runs. ♻️

Free to start

Learn DevOps Bootcamp with an AI tutor — free

Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.

Courses
142
Lessons
568

Frequently Asked Questions

Is the “allow_duplicates & Role Idempotency” lesson free?

Yes — any 3 lessons of the DevOps Bootcamp learning path, including “allow_duplicates & Role Idempotency”, are free to read in full here on the web. After that, CoddyKit PRO unlocks every lesson, plus interactive practice with a built-in code editor and a 24/7 AI tutor. The DevOps Bootcamp course includes 4 lessons in total.

What will I learn in “allow_duplicates & Role Idempotency”?

Control repeated role execution. You practise DevOps Bootcamp with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start DevOps Bootcamp?

No prior experience is required. DevOps Bootcamp on CoddyKit is structured for beginners through advanced learners, so you can start here or from the beginning and move at your own pace. This is lesson 4 of 4.

How long does the “allow_duplicates & Role Idempotency” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this DevOps Bootcamp lesson?

Yes. Every DevOps Bootcamp lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Role Dependencies in meta/main.yml
  2. defaults vs vars: The Override Order
  3. include_role & import_role at Runtime
  4. allow_duplicates & Role Idempotency
← Back to DevOps Bootcamp