roles and first_available_file + relative path

Hi,

I started to refactor my play books to roles as described in
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"
  tags: box_info
  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-
on-variables

- name: "[ntp] setup ntp.conf"
  action: template src=$item dest=/etc/ntp.conf backup=no owner=root
group=root mode=0644
  first_available_file:
    - ntp/ntp.conf.$ansible_fqdn.j2
    - ntp/ntp.conf.$ansible_distribution.j2
    - ntp/ntp.conf.default.j2
  tags: ntp
  notify:
    - restart service ntp

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

lookup plugins do not yet know about role basedirs.

There’s a ticket open on this.

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 :wink:

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

Best regards
Peter

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 :slight_smile: