# Specifying collections required by required roles

**URL:** <https://forum.ansible.com/t/specifying-collections-required-by-required-roles/37199>\
**Category:** Ansible Project\
**Created:** [October 10, 2022, 1:35pm UTC](https://forum.ansible.com/t/specifying-collections-required-by-required-roles/37199 "2022-10-10T13:35:15Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![utoddl](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/utoddl/32/249_2.png) [@utoddl](https://forum.ansible.com/u/utoddl)\
**Post date:** [October 10, 2022, 1:35pm UTC](https://forum.ansible.com/t/specifying-collections-required-by-required-roles/37199/1 "2022-10-10T13:35:15Z")

</div>

We have a handful of “common” roles that are used by many of our Ansible projects. These projects list their required roles in their respective roles/requirements.yml files. Nothing surprising here; it’s worked this way for years.

With recent maintenance, one of these “common” roles has started using bits from a couple of collections — community.general and ansible.utils. From reading the docs, I erroneously thought I could specify those collections in meta/requirements.yml like so:

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [October 10, 2022, 1:41pm UTC](https://forum.ansible.com/t/specifying-collections-required-by-required-roles/37199/2 "2022-10-10T13:41:06Z")

</div>

You should generally not do this. If you have content that is distributed, it should only rely on others of its type. A standalone role on a standalone role, or a collection on a collection. Note that collections can contain roles.

As such, there is no automatic installation of dependencies.

Should you wish to keep your use of standalone roles with dependencies on collections you would just have to rely on documentation. And maybe insert some form of canary test, that tries to use a module you need, wrapped in a block/rescue that then provides a friendly error when the module is not available.

---

<div class="post-metadata">

**Author:** ![Richard\_Megginson](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/richard_megginson/32/4540_2.png) [@Richard\_Megginson](https://forum.ansible.com/u/Richard_Megginson)\
**Post date:** [October 10, 2022, 2:00pm UTC](https://forum.ansible.com/t/specifying-collections-required-by-required-roles/37199/3 "2022-10-10T14:00:41Z")

</div>

Right - there is no mechanism in Ansible to do this. This is what we did for linux system roles - [https://linux-system-roles.github.io/documentation/role-requirements.html](https://linux-system-roles.github.io/documentation/role-requirements.html) - basically, made up our own file and rely on documentation.

---

<div class="post-metadata">

**Author:** ![utoddl](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/utoddl/32/249_2.png) [@utoddl](https://forum.ansible.com/u/utoddl)\
**Post date:** [October 10, 2022, 3:25pm UTC](https://forum.ansible.com/t/specifying-collections-required-by-required-roles/37199/4 "2022-10-10T15:25:30Z")

</div>

Alas, these projects all run on AWX, so we can’t rely on documented extra steps. It needs to work using the existing AWX scm update processes.

We get away with it as long as the required collections are already installed in one of the collection path directories. And they often will be on local workstations or AWX. But we obviously can’t rely on that.

We’ll either have to move these roles into our “collection-common” project from which we build our common collection, adding the dependencies to galaxy.yml there, or we’ll need to ensure through our CI pipelines that projects pulling in the common roles include their required collections in each project’s collections/requirements.yml.

This is not at all the answer I was expecting. But at least I can quit trying to make the unworkable work.

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [October 10, 2022, 3:28pm UTC](https://forum.ansible.com/t/specifying-collections-required-by-required-roles/37199/5 "2022-10-10T15:28:49Z")

</div>

If you are using awx, you can just create a `collections/requirements.yml` file that can specify those needed collections.

See: [https://github.com/ansible/awx/blob/devel/docs/collections.md](https://github.com/ansible/awx/blob/devel/docs/collections.md)

---

<div class="post-metadata">

**Author:** ![Walter\_Rowe](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/walter_rowe/32/4506_2.png) [@Walter\_Rowe](https://forum.ansible.com/u/Walter_Rowe)\
**Post date:** [October 11, 2022, 11:34am UTC](https://forum.ansible.com/t/specifying-collections-required-by-required-roles/37199/6 "2022-10-11T11:34:04Z")

</div>

This is what we do. When we know lots of different services and workflows require a given collection we add it to the AWX (Ansible Tower) controller so the projects themselves don’t have to worry about them.

Walter
