Jay Taylor's notes
back to listing indexHow to automatically install Ansible Galaxy roles?
[web search]
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. |
||||
You should use a
Then install them:
Here's a working example (installing OpenDaylight using Ansible as a Vagrant provisioner). See the relevant Ansible docs for more info. |
|||||||||
|
Another solution is to use git submodules. After all, Ansible Galaxy only is a directory of github repositories... I use this command to automatically add any Galaxy role as a submodule:
Commit the changes then to your git repo. When you clone your repo in future make sure to clone it with submodules, e.g. An advantage of this is, a git submodule is always referencing a specific version (git commit-hash). This will prevent you from running untested updates in your productive environment. A new version of a Galaxy role could have bugs or work completely different than before. With a git submodule you decide if and when you update a role to the new version. Also, you won't have to additionally take care of blacklisting galaxy roles in your |
||||
Some time ago I had exactly the same problem, and i have created a script for that. It gathers role dependencies from the meta/main.yml file, and then downloads them from ansible galaxy. You can find the script here: https://github.com/rtuin/ansible-install-dependencies I hope this is a solution for your problem. |
|||
As suggested, you can use ansible galaxy for this need. If you would like to further automate it then, you can add ansible galaxy inside your playbooks. For example:
|
|||
At this point in time, as far as I know there's no automatic way to download roles at runtime. Your best bet is to either commit them into your own repo or have a proper documentation listing all the requirements. You could even create a pre-flight playbook that installs your roles. :) |
|||||||||
|
Your Answer
asked |
1 year ago |
viewed |
3061 times |
active |
Get the weekly newsletter! In it, you'll get:
- The week's top questions and answers
- Important community announcements
- Questions that need answers
see an example newsletter
Related
Technology | Life / Arts | Culture / Recreation | Science | Other | ||
---|---|---|---|---|---|---|