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.


On Wednesday, April 25, 2018 at 6:18:22 AM UTC+10, Karl Auer wrote:
>
> 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:
>
> ---
> - hosts: localhost
>
>   roles:
>      - { role: local_role }
>      - { role: other_role }
>
> If I place other_role in my ./playbooks/roles directory:
>
>    mv /tmp/other_role ./playbooks/roles
>    ansible-playbook -v playbooks/test.yaml  --> both roles run
>  
> If I place other_role in my ./playbooks directory:
>
>    mv ./playbooks/roles/other_role ./playbooks
>    ansible-playbook -v playbooks/test.yaml  --> both roles run
>
> If I place other_role in my current working directory (my playbook 
> directory's parent) :
>
>    mv ./playbooks/other_role .
>    ansible-playbook -v playbooks/test.yaml  --> both roles run
>
> If I place other_role in /etc/ansible/roles:
>
>    sudo mv ./other_role /etc/ansible/roles
>    ansible-playbook -v playbooks/test.yaml  --> both roles run
>
> If I place other_role back in the /tmp directory (or anywhere else except 
> the above four locations), running the playbook produces a "role not found" 
> error:
>
>    mv ./other_role /tmp
>
> so it seems to me that the search path for roles contains at least these 
> four locations:
>
> - the current working directory
> - the directory containing the playbook
> - the roles directory relative to the directory containing the playbook
> - /etc/ansible/roles
>
> Plus the other two that ansible-config reports (that I didn't test):
> - ~/.ansible/roles
> - /usr/share/ansible/roles
>
> Is all this expected? In what order are these locations checked when a 
> role is referenced?
>
> Regards, K.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/6f951ad0-134b-43dd-988b-8cc352fb9f62%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to