Is there a cleaner way to use json_query to filter an array based on the value of an attribute?

15 views
Skip to first unread message

Behrang Saeedzadeh

unread,
Oct 17, 2017, 8:28:07 PM10/17/17
to Ansible Project
Hi,

The version of Ansible we are using does not support selectattr to filter a list based on attribute names. So I instead use something like this:

set_fact:
thing: '{{ (things | json_query("[?thing_name==''" + a_thing_name + "'']") | list)[0] }}'

Is there a cleaner way to do this? Without using double single-quotes for escaping and + for concatenation?
Reply all
Reply to author
Forward
0 new messages