Conditionally execute some tasks on dev hosts only

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

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.