Is there a cleaner alternative to '{{ (things | json_query("[?name==''" + thing_name + "'']") }}'

43 views
Skip to first unread message

Behrang Saeedzadeh

unread,
Oct 29, 2017, 8:55:31 PM10/29/17
to Ansible Project
Is there a cleaner alternative to:

    '{{ (things | json_query("[?name==''" + thing_name + "'']")  }}'

In particular, ideally I want to avoid:
  • String concatenation
  • Escaping of quotes

Pshem Kowalczyk

unread,
Oct 29, 2017, 10:00:41 PM10/29/17
to ansible...@googlegroups.com
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


--
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/e6e3df70-21f1-4fee-99da-b18de36727b2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Behrang Saeedzadeh

unread,
Oct 30, 2017, 7:16:32 AM10/30/17
to Ansible Project
Perfect! Thanks.
Reply all
Reply to author
Forward
0 new messages