On Tuesday, January 14, 2014 5:45:09 AM UTC-8, Michael DeHaan wrote:
>
> "syslog: "{% if ansible_distribution_version|truncate(1,true,'') >= '6' 
> %}rsyslog{% else %}syslog{% endif %}""
>
> That's super gross IMHO... I would not want to see that in *anyone's* 
> playbooks as that goes against much of the simplicity that Ansible seeks to 
> achieve.  
>
>
I hope that you are misunderstanding the context of this... If not then I 
am sorry to have offended you but this makes the entire task much simpler.  
I guess the question is where do you want the simplicity?

This is NOT in the playbook itself.  This is the setting of a variable in 
one of the group_vars files.

There is a completely separate thread about this which has had one response 
from someone which didn't work, but brought me to this point.

Here is a recap of the situation...

I have a task which sets up the base syslog configuration for both AIX and 
RedHat Linux.  Initially this was set up for RedHat Linux 6 where the 
configuration file is /etc/rsyslog.conf and the service needing restarted 
is rsyslog.  I then changed to a couple of variables because for AIX it's 
/etc/syslog.conf and the service is syslogd.  

At this point I have a dozen different set up tasks that work on RedHat 6 
and AIX.

Then I moved to checking the RedHat tasks on RedHat 5 as we have a bunch of 
older systems I would like to roll into the same system, and here is where 
I ran into an issue.  On RedHat 5 everything works identically EXCEPT that 
the syslog configuration file is /etc/syslog.conf and the service is 
syslog.  So I had questions about how to set those two variables 
appropriately.  Do I create a separate group_vars file for RedHat 5 and one 
for RedHat 6 for the difference of two variables?  Do I split the tasks out 
with and make them conditional on OS and version?  The simplest solution 
(it seems to me) is to have one task that is identical and set the 
variables appropriately, so that was my question.  Someone suggested 
setting the variables by setting them to the value of other variables that 
have the OS version as part of their name, I couldn't get that to work 
properly, and it still seemed somewhat inelegant.  The solution I ended up 
with was the line above.  

I have one group_vars file for AIX (no change needed) and one for RedHat.  
In the RedHat one I have that line of Jinja2 templating which sets the 
appropriate variable dependent on the OS version.

If you prefer I can rephrase it (so that it's clearer it's not talking 
about a module to 

variable: "{% if ansible_distribution_version|truncate(1,true,'') >= '6' 
%}value1{% else %}value2{% endif %}"

If you still don't like that then can I ask how you would do this?  
include_vars will only include additional variable files and while I could 
do that in the task (or it's accompanying handler) it would only make the 
task less simple.  group_by has the same issue...  This has the task as 
simple as possible and fully reusable while not creating more and more 
distinct OS groups.

I can send you the complete task, handler and accompanying group_vars files 
if you want to see everything...  This is just an excerpt to show the 
pattern, but it is simple.

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 ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to