Best practices for repository structure: Is it recommended to host Ansible roles in subdirectories?

Hi everyone,

I am currently working on optimizing our project structure. We are using a monorepo approach and I am considering placing our Ansible roles inside a specific subfolder (e.g., /ansible/roles/my_role/).

I have two main questions regarding this setup:

  1. Architecture: Is hosting an Ansible role within a subdirectory of a larger repository considered a standard “best practice”? Or is it strongly recommended to maintain roles in their own dedicated repositories?
  2. Technical Implementation: If the subdirectory approach is acceptable, how can I configure the requirements.yml file to correctly target and install only that specific subdirectory using ansible-galaxy role install?

I have looked into the documentation, but I am struggling to find the correct syntax for partial repository imports. Any guidance, community feedback, or links to relevant resources would be greatly appreciated.

Thank you in advance for your help!

Hi @Yoann.

Organize your roles into collections. One collection = one repository. You can then pull the collections with ansible-galaxy collection install -r requirements.yml and use the roles you need in the project. Yeah, it will probably pull more roles that you really need but if you keep your collection with a well define scope, even that will not be an issue.

I would say this is the “best practice” way and most easy one to understand and implement.