Ansible role dependency handling for collections

Viewed 1661

When creating an ansible role you can specify the dependencies in meta/main.yml as follows

dependencies:
- role: papanito.xxx

How I do this, if papanito.xxx was converted into a collection? Or let's phrase it otherwise: How to I tell my role, that it depends on a module/role from a collection?

If I run ansible-playbook which uses a role, that has a dependency to a role in a collection, get the following error:

ERROR! the role 'papanito.xxx' was not found in ansible.legacy:
/home/papanito/Workspaces/devenv/roles:
/home/papanito/.ansible/roles:
/usr/share/ansible/roles:
/etc/ansible/roles:
/home/papanito/Workspaces/devenv/roles:
/home/papanito/Workspaces/devenv

As I can see ansible checks these paths for roles, however, collections are stored under /home/papanito/.ansible/collections/ansible_collections/.

I suspect this has to do with the mention of ansible.legacy, however I did not configure anything like that - intentionally at least.

Using role: the_namespace.the_collection.the_role does not solve the problem, but I still get the same error.

Further the documentation says

Within a role, you can control which collections Ansible searches for the tasks inside the role using the collections keyword in the role’s meta/main.yml

So I updated meta/main.yml to

collections:
- papanito.xxx
dependencies:
- role: papanito.xxx.xxx

Which still results in the exact same error as above when I run the playbook.

1 Answers

So apparently this is not really supported. A detailed explication can be found in issue #76030

A stand alone role is not meant to depend on a collection, just as a collection is not meant to depend on a stand alone role.

It can be achieved technically, but users will be required to resolve the dependencies manually.

As such, collections should only depend on collections, and stand alone roles should only depend on stand alone roles.

Related