# Roles in collection and AWX

**URL:** <https://forum.ansible.com/t/roles-in-collection-and-awx/2147>\
**Category:** Get Help\
**Tags:** awx, collections, galaxy-ng\
**Created:** [November 4, 2023, 6:33pm UTC](https://forum.ansible.com/t/roles-in-collection-and-awx/2147 "2023-11-04T18:33:23Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![dkoci](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dkoci/32/815_2.png) [@dkoci](https://forum.ansible.com/u/dkoci)\
**Post date:** [November 4, 2023, 6:33pm UTC](https://forum.ansible.com/t/roles-in-collection-and-awx/2147/1 "2023-11-04T18:33:23Z")

</div>

Hi.  
I have my own collection with some roles in it. I have collections/requirements.yml file. I install collection with

`ansible-galaxy collection install -r collections/requirements.yml -p collections`

I also have `colletions_paths = ./collections` in ansible.cfg.

Part of my playbook looks like:

```auto
...
roles:
  - role: mynamespace.mycollection.my_role
...

```

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?

Thank you

---

<div class="post-metadata">

**Author:** ![jbericat](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jbericat/32/627_2.png) [@jbericat](https://forum.ansible.com/u/jbericat)\
**Post date:** [November 4, 2023, 8:45pm UTC](https://forum.ansible.com/t/roles-in-collection-and-awx/2147/2 "2023-11-04T20:45:45Z")

</div>

Hello,

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`

```auto
[defaults]
collections_path = "/home/user/.ansible/collections:/usr/share/ansible/collections:./collections:$ANSIBLE_HOME/collections"

```

Cheers

---

<div class="post-metadata">

**Author:** ![dkoci](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dkoci/32/815_2.png) [@dkoci](https://forum.ansible.com/u/dkoci)\
**Post date:** [November 4, 2023, 11:19pm UTC](https://forum.ansible.com/t/roles-in-collection-and-awx/2147/3 "2023-11-04T23:19:20Z")

</div>

@jbericat thank you, but your solution is not working in AWX, only locally.

---

<div class="post-metadata">

**Author:** ![jbericat](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jbericat/32/627_2.png) [@jbericat](https://forum.ansible.com/u/jbericat)\
**Post date:** [November 5, 2023, 9:40am UTC](https://forum.ansible.com/t/roles-in-collection-and-awx/2147/4 "2023-11-05T09:40:53Z")

</div>

Ok let me try it myself because that is something I do every now and then… I’ll get back to you shortly

---

<div class="post-metadata">

**Author:** ![jbericat](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jbericat/32/627_2.png) [@jbericat](https://forum.ansible.com/u/jbericat)\
**Post date:** [November 5, 2023, 10:38am UTC](https://forum.ansible.com/t/roles-in-collection-and-awx/2147/5 "2023-11-05T10:38:05Z")

</div>

Hello again,

Here in this repo I created a test collection with just one role:

[https://github.com/jbericat/ansible-forum](https://github.com/jbericat/ansible-forum)

Then I created a Job template from the `test_forum_dkoci.yml` playbook and I ran it on my AWX 23.0.0:

 ![image](https://us1.discourse-cdn.com/ansible/original/2X/8/8e59c6f09e6f9e84e4188a808e32adaa4271fa30.png)

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…

Hope it helps!

---

<div class="post-metadata">

**Author:** ![tanganellilore](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/tanganellilore/32/178_2.png) [@tanganellilore](https://forum.ansible.com/u/tanganellilore)\
**Post date:** [November 5, 2023, 11:57am UTC](https://forum.ansible.com/t/roles-in-collection-and-awx/2147/6 "2023-11-05T11:57:23Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dkoci](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dkoci/32/815_2.png) [@dkoci](https://forum.ansible.com/u/dkoci)\
**Post date:** [November 5, 2023, 12:32pm UTC](https://forum.ansible.com/t/roles-in-collection-and-awx/2147/7 "2023-11-05T12:32:46Z")

</div>

@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.

My collections/requiremets.yml looks like

collections:

- name: git+https://mygitlab/mynamespace.mycollection.git

---

<div class="post-metadata">

**Author:** ![jbericat](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jbericat/32/627_2.png) [@jbericat](https://forum.ansible.com/u/jbericat)\
**Post date:** [November 5, 2023, 12:40pm UTC](https://forum.ansible.com/t/roles-in-collection-and-awx/2147/8 "2023-11-05T12:40:20Z")

</div>

Hello,

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;

```auto
...
TASK [Fetch galaxy roles from requirements.(yml/yaml)] *************************
skipping: [localhost]
TASK [Fetch galaxy collections from collections/requirements.(yml/yaml)] *******
changed: [localhost] => (item=/var/lib/awx/projects/XXX/collections/requirements.yml)
PLAY RECAP ********************************************************************* localhost : ok=4 changed=1 unreachable=0 failed=0 skipped=2 rescued=0 ignored=0 

```

---

<div class="post-metadata">

**Author:** ![dkoci](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dkoci/32/815_2.png) [@dkoci](https://forum.ansible.com/u/dkoci)\
**Post date:** [November 5, 2023, 1:00pm UTC](https://forum.ansible.com/t/roles-in-collection-and-awx/2147/9 "2023-11-05T13:00:05Z")

</div>

Logs from project sync:

PLAY [Install content with ansible-galaxy command if necessary] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

TASK [Warn about disabled content sync] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

skipping: [localhost]

TASK [End play due to disabled content sync] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

skipping: [localhost]

TASK [Fetch galaxy roles from roles/requirements.(yml/yaml)] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

[WARNING]: Unable to find ‘/var/lib/awx/projects/\_11\_\_okd\_test\_files/roles’ in

expected paths (use -vvvvv to see paths)

skipping: [localhost]

TASK [Fetch galaxy collections from collections/requirements.(yml/yaml)] \*\*\*\*\*\*\*

[WARNING]: Unable to find

‘/var/lib/awx/projects/\_11\_\_okd\_test\_files/collections’ in expected paths (use

-vvvvv to see paths)

skipping: [localhost]

TASK [Fetch galaxy roles and collections from requirements.(yml/yaml)] \*\*\*\*\*\*\*\*\*

skipping: [localhost]

---

<div class="post-metadata">

**Author:** ![jbericat](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jbericat/32/627_2.png) [@jbericat](https://forum.ansible.com/u/jbericat)\
**Post date:** [November 5, 2023, 1:05pm UTC](https://forum.ansible.com/t/roles-in-collection-and-awx/2147/10 "2023-11-05T13:05:05Z")

</div>

> [@dkoci](#):
>
> [WARNING]: Unable to find ‘/var/lib/awx/projects/\_11\_\_okd\_test\_files/roles’ in

> [@dkoci](#):
>
> [WARNING]: Unable to find
> 
> ‘/var/lib/awx/projects/\_11\_\_okd\_test\_files/collections’ in expected paths (use
> 
> -vvvvv to see paths)

> [@dkoci](#):
>
> TASK [Fetch galaxy roles and collections from requirements.(yml/yaml)] \*\*\*\*\*\*\*\*\*
> 
> skipping: [localhost]

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](https://docs.ansible.com/ansible/latest/collections_guide/collections_installing.html#install-multiple-collections-with-a-requirements-file)

```auto
collections:
  - name: https://github.com/organization/repo_name.git
    type: git
    version: devel

```

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.

PS: On what version of AWX are you, btw?

---

<div class="post-metadata">

**Author:** ![dkoci](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dkoci/32/815_2.png) [@dkoci](https://forum.ansible.com/u/dkoci)\
**Post date:** [November 5, 2023, 1:27pm UTC](https://forum.ansible.com/t/roles-in-collection-and-awx/2147/11 "2023-11-05T13:27:40Z")

</div>

Ok the catch is to move collections/requirements.yml to the root of the project. It is working now.  
Thank you very much.

---

<div class="post-metadata">

**Author:** ![jbericat](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jbericat/32/627_2.png) [@jbericat](https://forum.ansible.com/u/jbericat)\
**Post date:** [November 5, 2023, 1:29pm UTC](https://forum.ansible.com/t/roles-in-collection-and-awx/2147/12 "2023-11-05T13:29:11Z")

</div>

Excellent!! I’m glad we could make it work at last

Have fun! 😉

---

<div class="post-metadata">

**Author:** ![tanganellilore](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/tanganellilore/32/178_2.png) [@tanganellilore](https://forum.ansible.com/u/tanganellilore)\
**Post date:** [November 5, 2023, 1:41pm UTC](https://forum.ansible.com/t/roles-in-collection-and-awx/2147/13 "2023-11-05T13:41:46Z")

</div>

Can your share your playbook repository path tree?

Because awx, as you can see in the log, search collections/roles requirements in different path.

If it nod found it, probably you choice the wrong file ame and/or wrong filepath.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [December 5, 2023, 1:42pm UTC](https://forum.ansible.com/t/roles-in-collection-and-awx/2147/14 "2023-12-05T13:42:34Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
