Would the following work?  For the few variables that differ, substitute 
them at the beginning of the playbook. It could even allow you to use a 
single variable file if you extrapolate all your variables in this manner.

vars:
   syslog_var: "{{ ansible_lsb.id }}_{{ ansible_lsb.major_release 
))_syslog_var"
   syslog_var2: "{{ ansible_lsb.id }}_{{ ansible_lsb.major_release 
))_syslog_var2"
and use {{ syslog_var }} in the tasks/templates.

Then in your RHEL vars file:
RedHat_5_syslog_var: foo
RedHat_6_syslog_var: bar
RedHat_5_syslog_var2: foo2
RedHat_6_syslog_var2: bar2

And similar for the AIX vars file.

You could use conditionals at the task level, or in templates, but if you 
only have a couple differences, I think this is a simpler method.

Lots of ways to accomplish this, depends on your wants and needs. My 
biggest concern is having others use/maintain the playbooks and being able 
to understand what's going on, and without having to grok the more 
difficult concepts. Ansible is pretty simple, but having a junior level 
sysadmin try to do things like address complex data or understanding 
variable precedence are items I'd like to avoid.

Brian

On Friday, January 10, 2014 7:19:12 PM UTC-6, Adam Morris wrote:
>
>
>
> On Friday, January 10, 2014 4:16:47 PM UTC-8, Brian Green wrote:
>>
>> How about keep your default variables in roles/vars/main.yml and then for 
>> variables that would be considered special case or overrides you put them 
>> elsewhere with higher precedence. For your RHEL 5 example, take a look at 
>> http://docs.ansible.com/playbooks_variables.html#conditional-imports and 
>> you could use something similar like
>> vars/{{  ansible_lsb.id }}_{{ ansible_lsb.major_release }}.yml  where 
>> you'd populate the RedHat_5.yml file with any of the variables you need 
>> overridden (my variable names/values might need some checking though).
>>
>> Brian
>>
>>
> I guess I wasn't as clear as I could have been...
>
> I currently have a single task that updates the syslog configuration file 
> and restarts the syslog daemon.  It works perfectly for AIX, RedHat 5 and 
> RedHat 6.  This is one of many tasks I have written so far.  
>
> The problem I have is that for most of my tasks I have differences between 
> RedHat and AIX that require variables...  So I had two variables files that 
> I am picking up, one for AIX and one for RedHat.  This is the one place 
> that RedHat 5 and RedHat 6 differ in a way that can easily be fixed with 
> variables (rsylog versus syslog)... But I either copy my RedHat variable 
> file and create two almost identical files with a difference of two lines 
> out of 11, or I find another way of doing this... 
>
> For the moment I've copied the RedHat file into RedHat5 and RedHat6.  I 
> was just wondering if there was a better way than treating RedHat 5 and 
> RedHat 6 as different operating systems.
>
> 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.

Reply via email to