Order of search when looking for roles directory

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

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

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

Yes, please send one, thanks!

Just sent: 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

This looks really good, in queue for testing.