Backticks don't work I see. This should do it:

       device_status: "{{ output | json_query('vedges[0].[\'side-id\']') }}"

On Mon, 7 Mar 2022 at 07:02, Dick Visser <[email protected]> wrote:
>
>
>
> On Mon, 7 Mar 2022 at 04:18, Delmiro Campelo <[email protected]> wrote:
>>
>> Hello Ansible friends,
>>
>> I'm hoping that you can provide some assistance here. I'm trying to parsed 
>> through json response from a web application, but I'm having some issues. 
>> The goal of this playbook is to display the site-id for all  routers in the 
>> json response. Any help is appreciated, thank you.
>>
>> Here is the ansible playbook.
>> - hosts: vmanage
>>   connection: local
>>   gather_facts: no
>>   tasks:
>>    - vmanage_device_facts:
>>        user: "{{ ansible_user }}"
>>        host: "{{ ansible_host }}"
>>        password: "{{ ansible_password }}"
>>      register: output
>>
>>    - name: Create device dictionary
>>      set_fact:
>>        device_status: '{{ output | json_query("vedges[0].["side-id"]")}}'
>
>
> Try quoting side-id with backticks
>
>
>
>>
>>
>>    - name: Print out site ids
>>      debug:
>>        msg: "{{ device_status }}"
>> ~
>> Error message after running the playbook is below:
>> PLAY [vmanage] 
>> **********************************************************************************************************************
>>
>> TASK [vmanage_device_facts] 
>> *********************************************************************************************************
>> [WARNING]: Module did not set no_log for password
>> ok: [10.10.2.2]
>>
>> TASK [Create device dictionary] 
>> *****************************************************************************************************
>> fatal: [10.10.2.2]: FAILED! => {"msg": "template error while templating 
>> string: expected token ',', got 'side'. String: {{ output | 
>> json_query(\"vedges[0].[\"side-id\"]\")}}"}
>>
>> PLAY RECAP 
>> **************************************************************************************************************************
>> 10.10.2.2                  : ok=1    changed=0    unreachable=0    failed=1  
>>   skipped=0    rescued=0    ignored=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 [email protected].
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/ansible-project/d0e826f5-1ad5-49cf-b429-dc87079f896bn%40googlegroups.com.
>
> --
> Sent from a mobile device - please excuse the brevity, spelling and 
> punctuation.



-- 
Dick Visser
Trust & Identity Service Operations Manager
GÉANT

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAL8fbwNe1KG645UqC62V4mvC2j%2B0TVmQ6SPBLbcoAy5NdfeSTQ%40mail.gmail.com.

Reply via email to