Conditionally execute some tasks on dev hosts only

27 views
Skip to first unread message

Shaunak Kashyap

unread,
Mar 24, 2014, 5:26:40 PM3/24/14
to ansible...@googlegroups.com
Hi,

I would like to conditionally execute some tasks within a play (or even the entire play itself) only if I'm setting up a development environment. What is the best way to perform such conditional execution?

One way I can think of is to define a variable (say "deploy_env=true") in my dev inventory file (hosts.dev), then use the "when" statement within the conditional tasks to look for that variable (i.e. when: deploy_env == true). Is this a good approach or is there a better way to define and run environment-specific tasks/plays?

Thanks,

Shaunak

Paul Durivage

unread,
Mar 26, 2014, 12:14:11 AM3/26/14
to ansible...@googlegroups.com
I think setting a variable is one straight forward way to go about solving the problem, conditionally running tasks if the variable is set. See this:  http://docs.ansible.com/playbooks_conditionals.html#applying-when-to-roles-and-includes

Another way is to create a group of devel servers in inventory or dynamically, and create a play that only runs on the devel group.
--
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/5a82dc55-9dbf-4c5b-a420-77c5c7a3af43%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages