# roles and first\_available\_file + relative path

**URL:** <https://forum.ansible.com/t/roles-and-first-available-file-relative-path/12878>\
**Category:** Ansible Project\
**Created:** [May 28, 2013, 12:42pm UTC](https://forum.ansible.com/t/roles-and-first-available-file-relative-path/12878 "2013-05-28T12:42:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hudec\_Peter](https://avatars.discourse-cdn.com/v4/letter/h/a87d85/32.png) [@Hudec\_Peter](https://forum.ansible.com/u/Hudec_Peter)\
**Post date:** [May 28, 2013, 12:42pm UTC](https://forum.ansible.com/t/roles-and-first-available-file-relative-path/12878/1 "2013-05-28T12:42:32Z")

</div>

Hi,

I started to refactor my play books to roles as described in  
[http://ansible.cc/docs/playbooks.html#roles](http://ansible.cc/docs/playbooks.html#roles).

If the task is in the role, the templates should be in the templates  
directory. This is working, for example in this scenario:

- name: "[box\_info] os production type identification"  
&nbsp;&nbsp;tags: box\_info  
&nbsp;&nbsp;action: template src=box\_info/box\_info.j2 dest=/etc/box\_info owner=root  
group=root mode=0644

If I try to use file selector based on template as described on  
[http://ansible.cc/docs/playbooks2.html#selecting-files-and-templates-based-](http://ansible.cc/docs/playbooks2.html#selecting-files-and-templates-based-)  
on-variables

- name: "[ntp] setup ntp.conf"  
&nbsp;&nbsp;action: template src=$item dest=/etc/ntp.conf backup=no owner=root  
group=root mode=0644  
&nbsp;&nbsp;first\_available\_file:  
&nbsp;&nbsp;&nbsp;&nbsp;- ntp/ntp.conf.$ansible\_fqdn.j2  
&nbsp;&nbsp;&nbsp;&nbsp;- ntp/ntp.conf.$ansible\_distribution.j2  
&nbsp;&nbsp;&nbsp;&nbsp;- ntp/ntp.conf.default.j2  
&nbsp;&nbsp;tags: ntp  
&nbsp;&nbsp;notify:  
&nbsp;&nbsp;&nbsp;&nbsp;- restart service ntp

I got error  
TASK: [[ntp] setup ntp.conf]

---

<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:** [May 28, 2013, 12:46pm UTC](https://forum.ansible.com/t/roles-and-first-available-file-relative-path/12878/2 "2013-05-28T12:46:07Z")

</div>

lookup plugins do not yet know about role basedirs.

There’s a ticket open on this.

---

<div class="post-metadata">

**Author:** ![Hudec\_Peter](https://avatars.discourse-cdn.com/v4/letter/h/a87d85/32.png) [@Hudec\_Peter](https://forum.ansible.com/u/Hudec_Peter)\
**Post date:** [May 28, 2013, 1:03pm UTC](https://forum.ansible.com/t/roles-and-first-available-file-relative-path/12878/3 "2013-05-28T13:03:16Z")

</div>

Hi Michael,

Thanks for quick answer.  
My next question is how will lookup plugin handle the lookup.  
The recommend directory structure is roles//{files, templates}.  
What in case there will be same filename in files and templates?

Generally I prefer to have common directory for files and templates and put “module” files in subdirectories like ‘ntp’, ‘ssh’, ‘zabbix’, …  
It would be also easier to write lookup plugin with roles support 😉

Do you think is hard to implement this feature in the lookup module ?

Best regards  
Peter

---

<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:** [May 28, 2013, 6:11pm UTC](https://forum.ansible.com/t/roles-and-first-available-file-relative-path/12878/4 "2013-05-28T18:11:53Z")

</div>

The idea is lookup plugins would obey the same rules (looking in files), so there’s a template lookup plugin, and I’m not sure about that yet. It might look in templates, TBD.

As for complexity, will have to see when I do it, but it’s not impossible 🙂
