# Reference collection root in role

**URL:** <https://forum.ansible.com/t/reference-collection-root-in-role/35356>\
**Category:** Ansible Project\
**Created:** [June 15, 2021, 8:47pm UTC](https://forum.ansible.com/t/reference-collection-root-in-role/35356 "2021-06-15T20:47:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mark\_Faine](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/mark_faine/32/7291_2.png) [@Mark\_Faine](https://forum.ansible.com/u/Mark_Faine)\
**Post date:** [June 15, 2021, 8:47pm UTC](https://forum.ansible.com/t/reference-collection-root-in-role/35356/1 "2021-06-15T20:47:42Z")

</div>

How can I do something like this from within a ROLE:

handlers:

- import\_tasks: {{ collection\_dir}}/handlers/apache.yaml

I see that doing this in a playbook that references the collection does work however there are two things broken with using it like this:

1. It makes all of the roles dependent on the playbook having a specific handlers section, they are no longer self-contained.

2. Molecule doesn’t know what to do with this and I can’t figure out how to test a role when the handlers don’t exist in the role.

Thanks,  
-Mark

BTW, looks like freenode is down.

---

<div class="post-metadata">

**Author:** ![felixfontein](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/felixfontein/32/7530_2.png) [@felixfontein](https://forum.ansible.com/u/felixfontein)\
**Post date:** [June 15, 2021, 9:09pm UTC](https://forum.ansible.com/t/reference-collection-root-in-role/35356/2 "2021-06-15T21:09:11Z")

</div>

Hi,

how about using `role_dir`? Then you can use that to compose a relative  
path from the current role's directory to your shared handlers file.

> BTW, looks like freenode is down.

We've moved to Libera.chat (since three weeks now; see  
[https://github.com/ansible-community/community-topics/issues/19](https://github.com/ansible-community/community-topics/issues/19)). It  
took a while to get all docs updated (probably some are still missing),  
but the official docs now point to Libera.chat:  
[https://docs.ansible.com/ansible/latest/community/communication.html#irc-channels](https://docs.ansible.com/ansible/latest/community/communication.html#irc-channels)

Cheers,  
Felix

---

<div class="post-metadata">

**Author:** ![Mark\_Faine1](https://avatars.discourse-cdn.com/v4/letter/m/ee59a6/32.png) [@Mark\_Faine1](https://forum.ansible.com/u/Mark_Faine1)\
**Post date:** [June 15, 2021, 9:35pm UTC](https://forum.ansible.com/t/reference-collection-root-in-role/35356/3 "2021-06-15T21:35:31Z")

</div>

Yes I have been trying role\_dir with a relative path but it’s not been working. Can I include a handlers section in the playbook tasks? That’s been the point of confusion for me.

I will update my bookmarks for libra chat. Thanks for the update.

-Mark

---

<div class="post-metadata">

**Author:** ![Mark\_Faine1](https://avatars.discourse-cdn.com/v4/letter/m/ee59a6/32.png) [@Mark\_Faine1](https://forum.ansible.com/u/Mark_Faine1)\
**Post date:** [June 15, 2021, 9:37pm UTC](https://forum.ansible.com/t/reference-collection-root-in-role/35356/4 "2021-06-15T21:37:04Z")

</div>

Excuse me, I meant to say:

Can I include a handlers section in the role tasks?
