On Monday, January 13, 2014 10:43:38 PM UTC-8, bryan hunt wrote:
>
> I had no idea that was possible, I've been using all sorts of kludges to
> achieve the same.
>
>
Me too, but I'm becoming more familar with Jinja2, and it really does make
a lot of this simpler when you can get it to work the way that you want. I
had a question about setting variables differently for different versions
of RedHat, and Brian Green suggested a nice attempt with multiple
variables, and setting the value of one variable to a different one
selected dynamically... In the end my final (Jinja2) answer was derived
from that concept but was much neater...
my group_vars/RedHat file now contains this...
syslog: "{% if ansible_distribution_version|truncate(1,true,'') >= '6'
%}rsyslog{% else %}syslog{% endif %}"
which sets the syslog variable correctly for RedHat depending on the
distribution version. The same role can also handle AIX for me, and
without having to create three similar tasks (two for RedHat variants and
one for AIX).
My one bit of advice from stuff I have learned in the last week would be
that as well as the Ansible documentation it is worth looking through the
Jinja2 documentation particularly... http://jinja.pocoo.org/docs/templates/
and the Expressions, Built-in Filters and Built-in Tests sections. There
are some additional filters documented in Ansible's documentation, but the
built-in ones are also useful.
I hope that this helps,
Adam
--
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].
For more options, visit https://groups.google.com/groups/opt_out.