foo.changed vs foo|changed

10 views
Skip to first unread message

Jason Gilfoil

unread,
Jan 14, 2019, 11:20:18 AM1/14/19
to Ansible Project
It's unfortunately exceedingly difficult to search for "|" in most search engines, so finding info about this was not fruitful.

My question is, is there a difference between foo.changed and foo|changed, especially used in a "when:" parameter?

If there's no difference, what's the preferred syntax?

Thanks!

Matt Martz

unread,
Jan 14, 2019, 11:54:14 AM1/14/19
to ansible...@googlegroups.com
There is a difference, in fact the preferred syntax is actually `when: foo is changed`

There is no guarantee that the attribute will exist on a returned object.  In addition to handling a non existent key/attribute, the changed test also has some more complex logic, where it will look into a sub-key called `results` too.

Historically we did not have jinja tests, which is what the `foo is changed` represents, so we registered them as filters (`foo|changed`).  We are deprecating using tests as filters, which is why the `is` syntax is preferred there.

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/20d7b6d0-99af-47b9-847c-92f4388224de%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Matt Martz
@sivel
sivel.net

Jason Gilfoil

unread,
Jan 14, 2019, 1:15:15 PM1/14/19
to Ansible Project
Thanks for the full and complete answer!
Reply all
Reply to author
Forward
0 new messages