Problem with json_query to search number

60 views
Skip to first unread message

dannyv...@gmail.com

unread,
Feb 4, 2021, 3:22:05 AM2/4/21
to Ansible Project
Hi all,

I am trying to search for a number with a json_query but result is always "".

Part of JSON is:

"json": {
        "code": 200,
        "success": true,
        "data": [
            {
                "vlanId": "430",
                "domainId": "3",
                "name": "Default",
                "number": "1",
                "description": "Default VLAN",
                "editDate": null,
                "customer_id": null,
                "custom_Topdesk": null
            },
            {
                "vlanId": "431",
                "domainId": "3",
                "name": "vlanname",
                "number": "3",
                "description": " vlanname  ",
                "editDate": null,
                "customer_id": null,
                "custom_Topdesk": null
            },

Ansible command i am using is:

- name: Determine VLAN ID      
      set_fact:
        vlan_id: "{{ ipam_vlans_filterby_domainid.content.data }} | json_query('[? number == ` ~ vlan ~ `]|[0].vlanId') }}"

variabele vlan for example is: "3"

I found on internet there are some bugs regarding this and some work arounds but not able to get it solved.
Does some one has an idea?

Kind regards,

Danny

Abhijeet Kasurde

unread,
Feb 4, 2021, 3:55:18 AM2/4/21
to ansible...@googlegroups.com
Try like

- debug:
msg: '{{ data | json_query(query) }}'
vars:
query: '[?number==`"{{ vlan }}"`]'

--
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 view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/7c2dcb43-ccc0-423b-8b4d-9fe69cfc585fn%40googlegroups.com.


--
Thanks,
Abhijeet Kasurde
Reply all
Reply to author
Forward
0 new messages