Jinja2 provides you with a built in test:
http://jinja.pocoo.org/docs/2.10/templates/#defined
So you can simply use:
However, if you're using Ansible variables, even thought you might have defined some of them as False they might still be treated as True as Jinja2 may simply see them as string variables.
So you should, and even encouraged to use the built-in bool filter. So the final and the safest answer is this:
http://jinja.pocoo.org/docs/2.10/templates/#defined
So you can simply use:
However, if you're using Ansible variables, even thought you might have defined some of them as False they might still be treated as True as Jinja2 may simply see them as string variables.
So you should, and even encouraged to use the built-in bool filter. So the final and the safest answer is this: