I have a Github repository that contains multiple roles, each in separate subdirectories. For example, I have separate roles ‘role-alpha’ and ‘role-beta’ in a repo at https://github.com/whoami/project.git each located in subdirectories as follows.
provisioning/roles/role-alpha
provisioning/roles/role-beta
I am trying to install these roles via a ‘requirements.yml’ file by running the following.
ansible-galaxy install -r requirements.yml
Can I install roles from a single Github repository that have multiple roles, each in unique subdirectories? What would the definition look like?
The role installation process does not support this at present. We’re in the middle of re-thinking how role installs work. If you’re interested, there is a proposal at github.com/ansible/ansible. Look in docs/proposals.
Combining multiple roles into a single repo makes things like testing, linting and versioning more complicated, so I don’t know that we really want to add this support. However, you can always suggest it and see what the community thinks.
However, there’s another use case where the support would be helpful. Which is keeping the ansible role in the same repo as the application it installs. So if I have github.com/myuser/mycoolapi.git I might want to keep the ansible role in a folder within the same mycoolapi that way the role can be versioned with the code it installs. Thoughts?
If you don’t mind making a tarball with the roles, you can use https://github.com/javiplx/ansible-library/, which is basically a install only private galaxy server, from where you can serve your packaged roles (so, it doesn’t matter the tree where they live).
If you want to pull down the entire Git repo and use the different roles within in it, you just need to have a meta/main.yml file at the repo root. See https://github.com/ansible/ansible/issues/16804 for details