# Order of search when looking for roles directory

**URL:** <https://forum.ansible.com/t/order-of-search-when-looking-for-roles-directory/12717>\
**Category:** Ansible Project\
**Created:** [April 24, 2013, 5:51pm UTC](https://forum.ansible.com/t/order-of-search-when-looking-for-roles-directory/12717 "2013-04-24T17:51:23Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matt\_Coddington](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Matt\_Coddington](https://forum.ansible.com/u/Matt_Coddington)\
**Post date:** [April 24, 2013, 5:51pm UTC](https://forum.ansible.com/t/order-of-search-when-looking-for-roles-directory/12717/1 "2013-04-24T17:51:23Z")

</div>

Hi all,  
I’ve just started experimenting with roles and noticed that play.py looks for the role in the current playbook’s directory first as opposed to under ./roles/ (e.g. looks for ./myrole/tasks/main.yml first before ./roles/myrole/tasks/main.yml). If it finds the ./myrole directory it assumes that’s the role directory and proceeds accordingly. Obviously having myrole in both places is confusing and I shouldn’t do that (this was just a result of me starting to move things from a non-role-based setup to a role-based one), but the order of search for roles feels backwards to me based on the recommendations at [http://ansible.cc/docs/bestpractices.html](http://ansible.cc/docs/bestpractices.html). Would a patch be accepted to first look for a role’s yml files in roles/ and _then_ try the local directory if it’s not found there?

This may also be helpful in explaining what I mean: [http://pastebin.com/v5H9CTFF](http://pastebin.com/v5H9CTFF)

Another patch I was considering is throwing an error if none of tasks/main.yml,vars/main.yml, OR handlers/main.yml exist under the role dir since that almost certainly implies a mistake in configuration… that would have saved me a bunch of time trying to figure out why my role wasn’t running any tasks (showing me that it was looking in ./myrole instead of roles/myrole).

thanks!  
matt

---

<div class="post-metadata">

**Author:** ![Serge\_van\_Ginderacht](https://avatars.discourse-cdn.com/v4/letter/s/b782af/32.png) [@Serge\_van\_Ginderacht](https://forum.ansible.com/u/Serge_van_Ginderacht)\
**Post date:** [April 24, 2013, 6:01pm UTC](https://forum.ansible.com/t/order-of-search-when-looking-for-roles-directory/12717/2 "2013-04-24T18:01:36Z")

</div>

> Would a patch be accepted to first look for a role's yml files in roles/  
> and \_then\_ try the local directory if it's not found there?

Trying the local dir first seems more natural to me, actually.  
​​

> Another patch I was considering is throwing an error if none of  
> tasks/main.yml,vars/main.yml, OR handlers/main.yml exist under the role dir  
> since that almost certainly implies a mistake in configuration... that  
> would have saved me a bunch of time trying to figure out why my role wasn't  
> running any tasks (showing me that it was looking in ./myrole instead of  
> roles/myrole).

Seems legit.​​

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [April 24, 2013, 6:22pm UTC](https://forum.ansible.com/t/order-of-search-when-looking-for-roles-directory/12717/3 "2013-04-24T18:22:15Z")

</div>

Yes, please send one, thanks!

---

<div class="post-metadata">

**Author:** ![Matt\_Coddington](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Matt\_Coddington](https://forum.ansible.com/u/Matt_Coddington)\
**Post date:** [April 26, 2013, 3:00am UTC](https://forum.ansible.com/t/order-of-search-when-looking-for-roles-directory/12717/4 "2013-04-26T03:00:35Z")

</div>

Just sent: [https://github.com/ansible/ansible/pull/2781](https://github.com/ansible/ansible/pull/2781)

Serge, I did end up submitting this with the search order changed (in addition the the error message mentioned) so it will search ./roles/myrole before ./myrole since that follows the what the bestpractices docs show and I think will otherwise end up continuing to trip up folks like me trying to convert their non-role structures into roles… just wanted to give an FYI there in case your opinion the other way was a really strong one!

matt

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [April 26, 2013, 12:18pm UTC](https://forum.ansible.com/t/order-of-search-when-looking-for-roles-directory/12717/5 "2013-04-26T12:18:29Z")

</div>

This looks really good, in queue for testing.
