Steve_Lee
(Steve Lee)
July 10, 2014, 10:39pm
1
Is it possible to have condition statement on variable? What would be the best way to assign Variable based on inventory group? Below is the basic idea.
vars:
epic: true
when: inventory_hostname == groups.database or inventory_hostname == groups.apache
vars:
epic: false
when: inventory_hostname != groups.database or inventory_hostname != groups.apache
Put them in a separate file and use the include_vars module:
http://docs.ansible.com/include_vars_module.html
You can use when: statements with that.
group_vars/ directories are the best way to do this in many cases.
Create a parent group that contains ‘database’ and ‘apache’ and apply the variables there.