0Pricing
Ansible Academy · Lesson

Role Dependencies in meta/main.yml

Chain roles that require others.

Role Dependencies in meta/main.yml is a free Ansible Academy lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Ansible Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Roles That Need Other Roles

Some roles only work if another role ran first. Your app role might need a base role to harden the server before it deploys.

Meet meta/main.yml

Every role can hold a meta/main.yml file. It stores role metadata like the author, supported platforms, and its dependencies.

The dependencies Key

Inside meta/main.yml, the dependencies key lists roles that must run before this one. Ansible applies them first, automatically.

dependencies:
  - role: common
  - role: firewall

Dependencies Run First

When you apply a role, Ansible runs its listed dependencies ahead of it, in the order they appear, then runs your role's own tasks.

Pass Variables to a Dependency

You can hand variables to a dependency right in the list. The base role runs configured exactly how this role needs it.

dependencies:
  - role: nginx
    vars:
      http_port: 8080

A Real Dependency Chain

A webapp role depends on nginx, which depends on common. Apply webapp and the whole chain resolves top to bottom for you.

Conditional Dependencies

A dependency can carry a when condition, so it only runs on hosts that match. Skip the firewall role on dev boxes, for example.

dependencies:
  - role: firewall
    when: env == 'prod'

Dependencies Are Static

Dependencies in meta are resolved before the play starts. They cannot use runtime facts gathered later, so keep their conditions simple.

Galaxy Reads meta Too

When you install a role from Ansible Galaxy, it reads meta/main.yml and pulls every dependency listed there automatically.

Keep Dependencies Honest

Only list a role as a dependency if it truly must run first. Hidden chains make automation hard to reason about and debug.

Galaxy Info Lives Here Too

Beyond dependencies, meta/main.yml holds galaxy_info: license, min Ansible version, and platforms. It documents how a role should be used.

Quick Check

Recall where you declare that one role must run before another.

Recap

List required roles under dependencies in meta/main.yml, and Ansible runs that chain first, optionally with vars and conditions. 🔗

Frequently asked questions

Is the “Role Dependencies in meta/main.yml” lesson free?

Yes — the full text of “Role Dependencies in meta/main.yml” is free to read here on the web, and the Ansible Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Ansible Academy course, upgrade to CoddyKit PRO.

What will I learn in “Role Dependencies in meta/main.yml”?

Chain roles that require others. You practise Ansible Academy 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 Ansible Academy?

No prior experience is required. Ansible Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Role Dependencies in meta/main.yml” 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 Ansible Academy lesson?

Yes. Every Ansible Academy 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 Ansible Academy