what would be the best way to set variable based on group

29 views
Skip to first unread message

Steve Lee

unread,
Jul 10, 2014, 6:39:20 PM7/10/14
to ansible...@googlegroups.com
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

James Cammarata

unread,
Jul 11, 2014, 2:57:11 PM7/11/14
to ansible...@googlegroups.com
Put them in a separate file and use the include_vars module:


You can use when: statements with that.



--
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-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/587e9f49-f9e4-4310-afc3-137c0bd9c5dd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Michael DeHaan

unread,
Jul 11, 2014, 6:33:23 PM7/11/14
to ansible...@googlegroups.com
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.



Reply all
Reply to author
Forward
0 new messages