The reason you get the error message is because you are accessing a variable that has never been set. It seems you are using the existence of extra-var as an indication that you want to install the composer (i.e. you never go through --extra-vars = "composer-install = false"), so you can go with is defined :
- shell: composer install when: composer-install is defined
But variables can be passed through filters, which can be useful for this case, because it still allows you to pass true / false, until it determines that the variable still works:
- shell: composer install when: composer-install|default(false)
Some additional conditions can be found here: http://docs.ansible.com/playbooks_conditionals.html
Jinja2 filters are very useful for several reasons, so more here: http://docs.ansible.com/playbooks_variables.html#jinja2-filters
And finally, a complete list of jinja2 built-in filters: http://jinja.pocoo.org/docs/dev/templates/#builtin-filters
source share