Search code examples
ansibleansible-role

Is there a way to specify the roles path in an ansible requirements.yaml?


I'm installing an ansible plugin with the following command

ansible-galaxy install -f -p /usr/share/ansible/plugins/lookup git+https://github.com/kemcon/ansible-modules-bitwarden

I would like to add this to my requirements.yml, but I don't know how to specify that roles_path parameter for this plugin only.

First place I checked was the galaxy user guide, but while it specifies how to set this on a command line install of a single plugin, it does not mention how to achieve this with the requirements.yml.

I've also tried simply specifying a path in the requirements.yml like this, with different variants for the name of the path parameter:

roles:
- src: https://github.com/kemcon/ansible-modules-bitwarden
  roles_path: /usr/share/ansible/plugins/lookup

But to no avail, the plugin is always installed into the same location as the other roles. I know I could specify ANSIBLE_ROLES_PATH as an environment variable, but that would affect all roles, not just this one.


Solution

  • Using ansible-galaxy to install modules is actually a hack, because the "right way" of distributing ansible modules is using collections. So if your module is not a part of collection - tough luck, you can't specify roles path in requirements file, only in ansible.cfg.

    You can maintain a separate requirements file, and invoke it with correct arguments using ansible-galaxy command from your question, and document it as a requirement in your README file.

    Also, there is a bitwarden lookup in community.general collection, maybe it can fit your usecase, and you won't need a separate module.

    Another way to solve your task is using Execution Environments to create an EE with lookup installed, however i'm not sure if it fits bitwarden usecase.