using json_query against integers?

12 views
Skip to first unread message

Justin DynamicD

unread,
Feb 13, 2019, 12:34:11 PM2/13/19
to Ansible Project
Ill let a fast sample bit of code do the talking:


---
- name: query test
  hosts: "localhost"
  gather_facts: no
  tasks:
    - set_fact:
        drives:
          - lun: 0
            size: "25gb"
          - lun: 1
            size: "100gb"

    - vars:
        json_query: "[?lun=='0']"
      set_fact:
        output: "{{ drives | json_query(json_query) }}"

    - debug:
        var: output



So in the above example, output = [], because json_query looks for a string and not an integer.  If I were to change the dictionary to use only strings I'd have no issues.

So ... does anyone know how to use json_query against integers?

Matt Martz

unread,
Feb 13, 2019, 12:38:50 PM2/13/19
to ansible...@googlegroups.com
Change your `json_query` var to use backticks (``) instead of quotes ('') around the 0

    - vars:
        json_query: "[?lun==`0`]"

--
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/cfdf4b9a-bf0b-43fc-acfd-1ac94c9cfe05%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Matt Martz
@sivel
sivel.net

Justin DynamicD

unread,
Feb 13, 2019, 12:47:39 PM2/13/19
to Ansible Project
NM all ... turns out i need the illustrious backtick (`) and not a single quote to denote a integer ...
Reply all
Reply to author
Forward
0 new messages