Is there a cleaner alternative to:
‘{{ (things | json_query("[?name==’‘" + thing_name + "’‘]") }}’
In particular, ideally I want to avoid:
-
String concatenation
-
Escaping of quotes
Is there a cleaner alternative to:
‘{{ (things | json_query("[?name==’‘" + thing_name + "’‘]") }}’
In particular, ideally I want to avoid:
String concatenation
Escaping of quotes
You can move the actual query string to a separate variable to reduce some clutter and string concatenation. You can also use ` (backticks) to quote jmes_path strings:
set_fact:
enabled_ports: “{{ intfs | json_query(enabled)}}”
vars:
enabled: “values(@)[?is_enabled && is_up && vlan_tag == {{ mgmt_vlan }}
]”
kind regards
Pshem
Perfect! Thanks.