It works fine unitl I try it to run on AWX which gives me an error
ERROR! the role 'mynamespace.mycollection.my_role' was not found in /runner/project/certificates/roles:/runner/requirements_roles:/runner/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles:/runner/project/certificates
My question is: Is it possible to use roles in collection with AWX templates?
Just adding $ANSIBLE_HOME/collections to collections_path should be enough. You don’t even need a requirements.yml file this way (I see you already installed the collection correctly on the project folder, so that must be it). I’m showing what I use myself on ./ansible.cfg
I suggest you compare your collection with mine, see what makes yours to fail when running on AWX. Just one thought here: Are you using ansible-galaxy collection init to create your collection folder structure, or did you build it from scratch? Your problem may be related to this…
Your role/Collection it’s published on ansible galaxy o is local to your playbook?
If it’s not published and is in separate repo respect to your playbook, you need to tell to awx wheree you need to download collection/role with src params in requirements.yml.
If role/Collection is inside your playbook, you need to have a folder tree like collections/ansible_collections/mynamespace/mycollection (as per example of @jbericat.)
If your Collection is in ansible galaxy, awx will download it automatically.
@jbericat Thank you for sharing the project. The difference between your project and mine is that I don’t have collections in the same project as the playbook. I have 2 gitlab projects. One contains collections, and the other contains the playbook where I want to use roles from the collection. The project with the playbook has a ‘collections’ directory with a ‘requirements.yml’ file containing the URL to the collection. As far as I know, AWX should install all the collections listed in ‘requirements.yml’ before running the template.
I see, thanks for sharing further details. I’ll replicate it again to illustrate my answer better.
Meanwhile, since I see you’re online now; try copying requirements.yml to the root of your project. Also; check & share your synced project log on AWX, it should look similar to this;
Here I see some clues. Try copying your requirements file to root as I said, it looks like AWX is searching for roles on this path → ./requirements.yml
Also, adjust its format to match the one suggested on the docs
EDIT: If you get your collection from Galaxy / Git Repo, you don’t have to install locally on the project, nor add the collection path to ansible.cfg (as pointed-out by @tanganellilore). If you want to run the roles locally with ansible-playbook you can just install the collection to user space (/home/user/.ansible). So, you may also try to delete the collection from the project folder and disable the custom ansible.cfg collection path settings.