Re: [ansible-project] Override a role's templates?

2019-01-31 Thread Kai Stian Olstad

On 31.01.2019 13:44, Dick Visser wrote:
BTW - Ideally I would like to be able to use the same inheritance 
structure

that is already in place for variables, in particular these concepts:

- group_templates/all
- group_templates/mygroup
- host_templates/myhost


Instead of template module use the copy module with content instead of 
src.


The template you have in a variable and use content like so.

- copy:
content: '{{ my_template }}'
dest: /tmp/test

--
Kai Stian Olstad

--
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 ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/3ab5805196585a8cd597466885635d68%40olstad.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] Override a role's templates?

2019-01-31 Thread S C Rigler
Maybe something like setting "NAGIOS_TEMPLATE: nagios_local.j2" in
your role's defaults then override NAGIOS_TEMPLATE (inventory variable
or whatever) as needed with a path to an alternate template.

On Thu, Jan 31, 2019 at 6:44 AM Dick Visser  wrote:
>
> Hi
>
> I'm using roles extensively to separate functionality, and I'm trying
> to keep the roles as general as possible. The resulting playbooks are
> very minimal, containing not more than a set of include_role tasks.
>
> Many roles use templates, which are stored inside the role's templates
> directory.
> Those templates can sometimes be quite specific, and are not usable in
> every scenario.
> So I'm looking for a way to 'override' the templates.
> Putting my custom template next to my playbook doesn't work, but it
> comes close. That path is included in the searchpath - but has lower
> priority:
>
> - role_path/templates
> - role_path
> - role_path/tasks/templates
> - role_path/tasks
> - playbook_dir/templates
> - playbook_dir
>
> So I ended up working around this by renaming the template and
> changing the template task to:
>
> - name: Ensure All-in-one Nagios configuration is available
>   template:
> src: "{{ item }}"
> dest: "/etc/nagios3/conf.d/local.cfg"
>   with_first_found:
> - nagios_local.j2  <-- custom template
> - _nagios_local.j2  <-- default template
>
> This does actually work, but it feels a bit kludgy.
> Is there a way to change the ordering of the items in the template searchpath?
>
>
> BTW - Ideally I would like to be able to use the same inheritance structure
> that is already in place for variables, in particular these concepts:
>
> - group_templates/all
> - group_templates/mygroup
> - host_templates/myhost
>
> The same can be said for 'files'.
>
> --
> Dick Visser
> Trust & Identity Service Operations Manager
> GÉANT
>
> --
> 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 ansible-project+unsubscr...@googlegroups.com.
> To post to this group, send email to ansible-project@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/ansible-project/CAL8fbwN3uChckJrf%3DofYTHyGcHhAaCSsTrxr%3DzCNB3kdzQo%2BBA%40mail.gmail.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
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 ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAFbiokeukrmEwfP5cLqtoqfWpJpMMSxRN0XBT2cs-PgxrCHg0w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] Override a role's templates?

2019-01-31 Thread Dick Visser
Hi

I'm using roles extensively to separate functionality, and I'm trying
to keep the roles as general as possible. The resulting playbooks are
very minimal, containing not more than a set of include_role tasks.

Many roles use templates, which are stored inside the role's templates
directory.
Those templates can sometimes be quite specific, and are not usable in
every scenario.
So I'm looking for a way to 'override' the templates.
Putting my custom template next to my playbook doesn't work, but it
comes close. That path is included in the searchpath - but has lower
priority:

- role_path/templates
- role_path
- role_path/tasks/templates
- role_path/tasks
- playbook_dir/templates
- playbook_dir

So I ended up working around this by renaming the template and
changing the template task to:

- name: Ensure All-in-one Nagios configuration is available
  template:
src: "{{ item }}"
dest: "/etc/nagios3/conf.d/local.cfg"
  with_first_found:
- nagios_local.j2  <-- custom template
- _nagios_local.j2  <-- default template

This does actually work, but it feels a bit kludgy.
Is there a way to change the ordering of the items in the template searchpath?


BTW - Ideally I would like to be able to use the same inheritance structure
that is already in place for variables, in particular these concepts:

- group_templates/all
- group_templates/mygroup
- host_templates/myhost

The same can be said for 'files'.

-- 
Dick Visser
Trust & Identity Service Operations Manager
GÉANT

-- 
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 ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAL8fbwN3uChckJrf%3DofYTHyGcHhAaCSsTrxr%3DzCNB3kdzQo%2BBA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.