Install Roles with requirements.yml
Pin and fetch dependencies.
Install Roles with requirements.yml is a free Ansible Academy lesson on CoddyKit — lesson 2 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.
Stop Installing By Hand
Running install commands one by one does not scale. A requirements.yml file lists every dependency so the whole project installs in one shot.
A Manifest for Dependencies
Think of requirements.yml as your package manifest: it declares exactly which roles and collections your playbooks need to run.
List Roles Under roles
Inside the file, a roles key holds a list. Each entry names one role to fetch from Galaxy by its author.name handle.
roles:
- name: geerlingguy.nginxList Collections Too
A separate collections key lists collections by their namespace.collection name, so one file covers both content types.
collections:
- name: community.generalPin a Version
Always add a version so installs are reproducible. Without it you may pull a newer, breaking release on a teammate's machine.
roles:
- name: geerlingguy.nginx
version: "3.1.4"Install Everything at Once
Point ansible-galaxy at the file with -r and it resolves and installs every listed dependency in a single command.
ansible-galaxy install -r requirements.ymlCollections Need Their Own Run
The plain install command handles roles. For collections, use the collection install subcommand with the same -r flag.
ansible-galaxy collection install -r requirements.ymlPull from Git, Not Just Galaxy
A role entry can use a src Git URL instead of a Galaxy name, letting you install private or unpublished roles.
roles:
- src: https://github.com/acme/role-app.git
version: mainChoose an Install Path
Add -p to drop roles into a project-local folder like roles/ instead of the global path, keeping each project self-contained.
ansible-galaxy install -r requirements.yml -p roles/Force a Refresh
By default existing roles are kept. Pass --force to re-download and overwrite them when you bump a pinned version.
ansible-galaxy install -r requirements.yml --forceCommit the File, Not the Roles
Check requirements.yml into Git but ignore the downloaded role folders. Anyone can rebuild the exact set from the manifest.
Quick Check
Recall how to install everything a project depends on.
Recap
List roles and collections in requirements.yml, pin versions, then install them all with ansible-galaxy -r. One file, reproducible setups. 📦
Frequently asked questions
Is the “Install Roles with requirements.yml” lesson free?
Yes — the full text of “Install Roles with requirements.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 “Install Roles with requirements.yml”?
Pin and fetch dependencies. 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 2 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Install Roles with requirements.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
- Roles vs Collections on Galaxy
- Install Roles with requirements.yml
- Using FQCN: namespace.collection.module
- Publishing Your Own Role to Galaxy