What's The Difference?

38 views
Skip to first unread message

Tennis Smith

unread,
Sep 25, 2015, 8:42:47 AM9/25/15
to Ansible Project
Hi,

What's the difference, if any, between these 2 constructs?

when: varname is none

...and...

when: varname | trim == ''

Are they equivalent, or is there a subtle difference?

-T

Brian Coca

unread,
Sep 25, 2015, 9:20:04 AM9/25/15
to Ansible Project
they are actually quite different.

None is a 'null' while '' is an empty string, different types. They
both evaluate to False so they would be equivalent here:

when: varname

but not in the specific tests you show, if varname is None, it would
error out in the 2nd test and the empty string would not match in the
first case.

--
Brian Coca

Tennis Smith

unread,
Sep 25, 2015, 9:46:31 AM9/25/15
to Ansible Project
Thanks, Brian!

So, "when: varname" is equivalent to both of my examples?

-T

Brian Coca

unread,
Sep 25, 2015, 9:49:14 AM9/25/15
to Ansible Project
not exactly, it will be false for the values of None and '' but not for ' '


--
Brian Coca
Reply all
Reply to author
Forward
0 new messages