'empty()' Jinja test?

Hi,

several times now I came across situation where one of the modules returns ‘empty list’ in variable and it would be handy to have a simple test like:

{% if foo is empty %}

which is not the same as

{% if foo is defined %}

because former case covers also “”, , {} and None as well as “undefined”. Sort of like “empty()” call in PHP.

Right now I’ve been managing situation with crutches like:

when: foo_list|join(‘’) != ‘’

but that is non-descriptive and hackish IMO. Is there an interest of adding this feature? Shall I post into Github issue tracker?

would this not work?
foo>length == 0

Since jinja2 uses python under the hood, you get the benefit of python truthiness checks. I would probably write this as:

{% if foo is defined and foo %}

In some cases this can be shortened to just:

{% if foo %}

The inverse to see if it is empty is:

{% if not foo %}