Interview Prep/Ansible/Roles, Collections and Galaxy

How do role dependencies work?

IntermediateConceptRoles, Collections and Galaxy
Answer

List them in meta/main.yml. Ansible runs dependencies before the role itself, in order.

# roles/app/meta/main.yml
dependencies:
  - role: common
  - role: java
    java_version: 17

Dependencies can pass parameters and are installed by ansible-galaxy when listed there with a source. Keep dependency chains shallow: hidden implicit roles make a play hard to reason about, so many teams prefer explicit ordering in the playbook.

All Ansible questions Roadmap: Ansible

More on Roles, Collections and Galaxy