Where to specify Ansible role's dependencies

It seems that Ansible Galaxy will understand it has to download dependencies if those are specified in either meta/main.yml or a requirements.yml file.

Is there a best practice for this?


TL;DR:

  • meta/main.yml is for roles-to-role dependency

  • requirements.yml is for playbook-to-role dependency.


Playbook can contain dependencies in meta/main.yml. Dependent roles will be installed during ansible-galaxy install, so if role A depends on role B, role B will be installed together with role A. Role B will be also applied before role A is applied automatically during ansible-playbook run.

Roles mentioned in requirements.yml are requirements of your local playbook. You can install roles from Galaxy with ansible-galaxy -r requirements.yml but the requirements.yml file is used only for your convenience of installing roles needed to run the playbook. No automatic/automagic execution of roles mentioned there should happen.