What is best practice to determine if object has property (ideally at any depth)?

17 views
Skip to first unread message

ja...@blendlabs.com

unread,
Jan 10, 2017, 7:16:13 PM1/10/17
to Ansible Project
What is the best way to test this condition?

when: "{{object is defined and object.property is defined and object.property.property is defined and object.property.property == 'mystring'}}"

A custom lookup?




Kai Stian Olstad

unread,
Jan 11, 2017, 3:50:21 AM1/11/17
to ansible...@googlegroups.com
What's best is always relative, but you could use this
when: ((object | default()).property | default()).property | default()
== 'mystring'

And remember, don't use curly brackets in when.

--
Kai Stian Olstad
Reply all
Reply to author
Forward
0 new messages