Hi!
Sorry for not copying hyperlinks, I hate that too - I guess I just got
too confortable with github doing that for me :)
I have written down a few use cases in my previous emails and the
ticket, but I will summarize them here again for simplicity's sake.
I have also just encountered another usecase, i'm detailing it as the first one.
The problem with the current setup is that by not being able to pass
in, rename, or specify how to look up input variables, it hinders
template reusability.
*** USE CASE 1 ***
I have a list of hosts, and for reasons outside the scope of this
discussion, I need to create a /etc/hosts.d directory containing one
entry per file, which will be concatenated into one /etc/hosts file by
an incron job.
So I'd like to do this:
- template: src=foo.j2, dest=/etc/hosts.d/{{item}}
dns={{hostvars[item].ansible_hostname}}.vpn
ip={{hostvars[item].ansible_tun0.ipv4.address}}
with_items: {{ groups["vpn-clients"] }}
And yes, I could use that complicated lookup within the template, but
would be mixing up layers. The tasks should know how to find out what
to render, and templates should be dead simple, just render what is
given to them.
And I couldn't reuse this template if I'd hardcode the way to look up
the tunnel0 interface address into them in case I would need (and I
do) to
add other interface addresses to the list, like so:
- template: src=foo.j2, dest=/etc/hosts.d/{{item}}
dns={{hostvars[item].ansible_hostname}}.public
ip={{hostvars[item].ansible_eth0.ipv4.address}}
with_items: {{ groups["all"] }}
**** USE CASE 2 ****
Due to openSSL not being able to accept extendedusagetypes from the
command line, only from config files, I need to generate a temporary
configuration file, so I would need to do something similar to this:
- template: src=openssl_config.j2 dest=/tmp/openssl.cnf usage=serverAuth
- name: sign client csrs
shell: openssl req -in {{item}} -config /tmp/openssl.cnf..... [sign items]
with_items: server_certs
- template: src=openssl_config.j2 dest=/tmp/openssl.cnf usage=clientAuth
- name: sign server csrs
shell: openssl req -in {{item}} -config /tmp/openssl.cnf .....
with_items: client_certs
**** USE CASE 3 ****
Very similar to Use case 1, it was mentioned by @ iraksdale in the
first Issue on Gtihub:
Have to agree with @claco here. I'm using a template to output
multiple files based on a with_dict loop, and semantically it kind of
sucks to use item.key or item.value all over the template - doesn't
make them very reusable.
It would be nice to define "service_name" or "hostname" variables or
whatever in the playbook where it's easy to see their relationship to
the variable being looped, and have the templates use {{service_name}}
instead of having to put "whatever_{{item.key}}" in the templates.
Regards,
Akos Vandra
>
https://groups.google.com/d/msgid/ansible-project/CA%2BnsWgy5yFATNdYS2Xa-neoi3hV7TDjFQRBAPjodNTxMP1VEQQ%40mail.gmail.com.