Question:
All my Ansible playbooks/roles are checked in to my git repo.
However, for Ansible Galaxy roles I always have to explicitly download them one by one on every machine I want to run Ansible from.
It’s even tough to know in advance exactly which Ansible Galaxy roles are needed until Ansible complains about a missing role at runtime.
How is one supposed to manage the Ansible Galaxy role dependencies? I would like to either have them checked into my git repo along with the rest of my ansible code or have them automatically be identified and downloaded when I run Ansible on a new machine.
Answer:
You should use a requirements.yml
file for this use-case. Describe the roles you require, using any of a variety of install methods:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# Install a role from the Ansible Galaxy - src: dfarrell07.opendaylight # Install a role from GitHub - name: opendaylight src: https://github.com/dfarrell07/ansible-opendaylight # Install a role from a specific git branch - name: opendaylight src: https://github.com/dfarrell07/ansible-opendaylight version: origin/master # Install a role at a specific tag from GitHub - name: opendaylight src: https://github.com/dfarrell07/ansible-opendaylight version: 1.0.0 # Install a role at a specific commit from GitHub - name: opendaylight src: https://github.com/dfarrell07/ansible-opendaylight version: |
Then install them:
1 2 |
ansible-galaxy install -r requirements.yml |
Here’s a working example (installing OpenDaylight using Ansible as a Vagrant provisioner). See the relevant Ansible docs for more info.