Setting a variable by conditional in a playbook

50 views
Skip to first unread message

Lars Sommer

unread,
May 26, 2014, 10:52:00 PM5/26/14
to ansible...@googlegroups.com
I have spent the last few hours trying to find a way to do this and keep running into formatting issues with every suggestion I find. 
What I am trying to accomplish is to have a variable that is set based on the value of another variable.

So if {{ group }} == dev* then I want to set uwsgi_env: development
but if {{ group }} == prod* then I want to set uwsgi_env: production

This seems really reasonable, is there a simple way to accomplish this in a playbook?

Brian Coca

unread,
May 27, 2014, 10:42:38 AM5/27/14
to ansible...@googlegroups.com
I just set uwsgi_env in group_vars/{production,development}, but you should be able to do this also use set_fact and when to do the same.​

Michael DeHaan

unread,
May 27, 2014, 4:02:27 PM5/27/14
to ansible...@googlegroups.com
+1 to group_variables over set_fact.   It's more native and probably more intuitive.

set_fact should only be used for really oddball niche scenarios, like when you need to multiply a number by 10 or round a value, etc.




On Tue, May 27, 2014 at 10:42 AM, Brian Coca <bria...@gmail.com> wrote:
I just set uwsgi_env in group_vars/{production,development}, but you should be able to do this also use set_fact and when to do the same.​

--
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/CADn%2BHszJ-n6BtDFwebviuxWC8Mj6Gw-u3SOe9AdrGJjwaoBhnw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages