# How to see roles search path?

**URL:** <https://forum.ansible.com/t/how-to-see-roles-search-path/27364>\
**Category:** Ansible Project\
**Created:** [April 24, 2018, 8:18pm UTC](https://forum.ansible.com/t/how-to-see-roles-search-path/27364 "2018-04-24T20:18:21Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Karl\_Auer](https://avatars.discourse-cdn.com/v4/letter/k/cc9497/32.png) [@Karl\_Auer](https://forum.ansible.com/u/Karl_Auer)\
**Post date:** [April 24, 2018, 8:18pm UTC](https://forum.ansible.com/t/how-to-see-roles-search-path/27364/1 "2018-04-24T20:18:21Z")

</div>

Is there any way to output the roles\_path in a task (not the specific path to a role, I mean the search path)?

The doco for Ansible 2.5 says that roles are found in the ./roles directory relative to the playbook file, and in /etc/ansible/roles.

“ansible-config list” says that roles are also found in ~/.ansible/roles, /usr/share/ansible/roles and /etc/ansible/roles - the first two are not mentioned in the doco.

It seems to me from my testing that roles are also found in the current working directory, and in the playbooks directory.

I have a role called other\_role (i.e., a directory called other\_role, containing a tasks directory containing main.yaml) in /tmp.

As a control, I have another role called local\_role in ./playbooks/roles

Finally I have an extremely simple playbook in ./playbooks that references the roles:

---

<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:** [April 24, 2018, 8:25pm UTC](https://forum.ansible.com/t/how-to-see-roles-search-path/27364/2 "2018-04-24T20:25:27Z")

</div>

You can use `lookup('config', 'DEFAULT_ROLES_PATH')`to get the  
configured ones, but that won't include the adjacent to playbook, but  
{{playbook\_dir}}/roles would give you that.

---

<div class="post-metadata">

**Author:** ![Karl\_Auer](https://avatars.discourse-cdn.com/v4/letter/k/cc9497/32.png) [@Karl\_Auer](https://forum.ansible.com/u/Karl_Auer)\
**Post date:** [April 24, 2018, 11:43pm UTC](https://forum.ansible.com/t/how-to-see-roles-search-path/27364/3 "2018-04-24T23:43:22Z")

</div>

Thanks, Brian.

It’s disappointing not to be able to get the actual search path. This means that the doc is wrong (or at least incomplete), so one has to “just know” that a role can also be in the current working directory, in the playbook directory, and in two other secret locations - as well as the documented ones.

The reason I was looking for this information is that I need to add a path to the roles search path. I began an experiment to see if the ansible.cfg “roles\_path” variable would be added to or override the defaults. I still haven’t done that experiment, because I got distracted by the question of how to locate the search path at all 🙂

I discovered the playbook directory component because I initially moved my test role there (out of the ./playbook/roles directory) thinking that would prevent it from being found, and was surprised to see it still ran… so I moved it up to my current working directory (above the playbooks directory) and was surprised again to see that it STILL ran!

IMHO a way to see the _actual_ search path, rather than just the default or configured parts of it, would be useful.

Regards, K.

---

<div class="post-metadata">

**Author:** ![Karl\_Auer](https://avatars.discourse-cdn.com/v4/letter/k/cc9497/32.png) [@Karl\_Auer](https://forum.ansible.com/u/Karl_Auer)\
**Post date:** [April 24, 2018, 11:52pm UTC](https://forum.ansible.com/t/how-to-see-roles-search-path/27364/4 "2018-04-24T23:52:33Z")

</div>

I should mention that the complete path with all components does show up in the error message when a role is missing 🙂

Regards, K.

---

<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:** [April 25, 2018, 10:01pm UTC](https://forum.ansible.com/t/how-to-see-roles-search-path/27364/5 "2018-04-25T22:01:30Z")

</div>

FYI, cwd is not in the searchpath, its relative to the playbook, not  
the cwd. I did give you the way to get the full list, just need to  
consult 2 variables.

---

<div class="post-metadata">

**Author:** ![Karl\_Auer](https://avatars.discourse-cdn.com/v4/letter/k/cc9497/32.png) [@Karl\_Auer](https://forum.ansible.com/u/Karl_Auer)\
**Post date:** [April 25, 2018, 11:02pm UTC](https://forum.ansible.com/t/how-to-see-roles-search-path/27364/6 "2018-04-25T23:02:32Z")

</div>

Thanks, Brian.

You are right; I conflated two results. I just re-tested that aspect; a role will not be found merely because it is in the CWD.

Regards, K.

---

<div class="post-metadata">

**Author:** ![Karl\_Auer](https://avatars.discourse-cdn.com/v4/letter/k/cc9497/32.png) [@Karl\_Auer](https://forum.ansible.com/u/Karl_Auer)\
**Post date:** [April 25, 2018, 11:16pm UTC](https://forum.ansible.com/t/how-to-see-roles-search-path/27364/7 "2018-04-25T23:16:02Z")

</div>

I spoke too soon.

A role placed in the current working directory WILL be located and run, even if it is not explicitly in the default roles path NOR in the roles\_path defined in ansible.cfg.

This is with Ansible 2.5.1. Try it…

Regards, K.

---

<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:** [April 26, 2018, 12:53am UTC](https://forum.ansible.com/t/how-to-see-roles-search-path/27364/8 "2018-04-26T00:53:03Z")

</div>

I cannot reproduce, i only get roles/ from cwd if I cd to the play  
directory and it has an adjacent roles/.

But that is not that it searches cwd, it just happens to coincide with  
the play's directory.

---

<div class="post-metadata">

**Author:** ![Karl\_Auer](https://avatars.discourse-cdn.com/v4/letter/k/cc9497/32.png) [@Karl\_Auer](https://forum.ansible.com/u/Karl_Auer)\
**Post date:** [April 26, 2018, 5:49am UTC](https://forum.ansible.com/t/how-to-see-roles-search-path/27364/9 "2018-04-26T05:49:24Z")

</div>

I’ve just done some testing, and a role in the current working directory WILL be used, but only if the role cannot be found elsewhere. This is with Ubuntu 16.04 and Ansible 2.5.1.

I haven’t worked out the precedence yet, but it appears to be :

- the roles directory below the directory containing the playbook
- the elements of roles\_path from left to right (two elements in my case)  
OR
- the elements of the DEFAULT\_ROLES\_PATH from left to right (three elements)
- the directory the playbook is in
- the current working directory

To test this, I put a test role in each of the eight possible locations (my CWD test was from /tmp) then renamed them all so that the playbook would be unable to find them. I then ran the playbook and got the expected failure to find the role. Then I renamed the role in each of the locations in turn, to the name expected by the playbook, checked that the playbook could find it, then renamed it away again.

One surprise was that although the comment in the distributed ansible.cfg says that the roles\_path variable is for “additional paths to search for roles in”, in fact roles\_path will, if specified, REPLACE the defaults.

On my system the default role paths (i.e., with no roles\_path specified in ansible.cfg) are ~/.ansible/roles, /usr/share/ansible/roles, and /etc/ansible/roles.

Regards, K.

---

<div class="post-metadata">

**Author:** ![Karl\_Auer](https://avatars.discourse-cdn.com/v4/letter/k/cc9497/32.png) [@Karl\_Auer](https://forum.ansible.com/u/Karl_Auer)\
**Post date:** [April 26, 2018, 5:51am UTC](https://forum.ansible.com/t/how-to-see-roles-search-path/27364/10 "2018-04-26T05:51:59Z")

</div>

Sorry, that OR in the precedence applies only to the one item above and the one item below it.
