1

I'm running ansible within terraform.

I downloaded a galaxy role using:

ansible-galaxy install <role>

This downloaded it to my ~/.ansible/roles directory.

But when I referenced the role name in my ansible playbook that I use with terraform, it couldn't find it.

So instead I specified a directory like so:

ansible-galaxy install --roles-path . <role>

While this now works, it's mixed in with all my other scripts that are under source control.

I'm wondering if there's a way to use a galaxy role without actually downloading it? Or if there's a way to specify in my ansible playbook where to look for additional roles besides my roles?

Nathan
  • 7,627
  • 11
  • 46
  • 80
  • [This question (and answer) about `requirements.yml` for role downloads](https://stackoverflow.com/q/55773505/9401096) might give you some ideas on how to organize your project. – Zeitounator Jan 10 '21 at 14:27
  • Is there a way to trigger the download of the requirements file in the playbook? Or do I need to run the command manually before the playbook? – Nathan Jan 15 '21 at 04:05
  • 1
    This is not done in a playbook (although I never tried....). You have to do it right after you git cloned/pull your project. AWX/Tower does this automatically. – Zeitounator Jan 15 '21 at 05:19

1 Answers1

2

Since Ansible only knows how to retrieve roles from the local filesystem, you must download roles before you can use them.

You can tell Ansible where to look for roles by setting the ANSIBLE_ROLES_PATH environment variable, or by setting roles_path in your ansible.cfg. See the documentation for details.

larsks
  • 277,717
  • 41
  • 399
  • 399