https://jmespath.org/tutorial.html is a good start, the examples have
the data in editable forms, so you can quickly test things out.
For trial/error with complex data structures that come from
expensive/slow APIs or playbooks, I usually make a dummy playbook with
hard coded data, to focus on the json_query part itself, for example:
---
- hosts: localhost
connection: local
gather_facts: no
vars:
chum: |
[
{
"DistinguishedName": "CN=LASTNAME\\, FIRSTNAME
(USN123),OU=Users,OU=ORGANIZATION,DC=CONSONTO,DC=net",
"SamAccountName": "USN123"
},
{
"DistinguishedName": "CN=LASTNAME1\\, FIRSTNAME1
(USN234),OU=Users,OU=ORGANIZATION,DC=CONSONTO,DC=net",
"SamAccountName": "USN234"
}
]
tasks:
- set_fact:
test: "{{ chum|from_json|json_query('[].SamAccountName') }}"
- debug: var=test
On Fri, 6 Nov 2020 at 18:30, [email protected] <[email protected]> wrote:
>
> That absolutely worked and made a huge difference.
>
> so using [] like that selects all entries from the variable being piped into
> it to query?
> Is there literature I can read to help understand this facet better?
>
> Thank you again!.
>
> On Friday, November 6, 2020 at 12:05:20 PM UTC-5 [email protected] wrote:
>>
>> On Thu, 5 Nov 2020 at 23:17, [email protected] <[email protected]> wrote:
>>
>> > - name: plate SamAccountName's
>> > set_fact:
>> > caughtfish: "{{ chum | json_query(jmesquery) }}"
>> > vars:
>> > jmesquery: 'chum.SamAccountName'
>>
>> You are already piping 'chum' to json_query, so it should not be part
>> of the query itself again.
>> Also, because it's a list, you need to select all entries first with [].
>> And a relatively simple query like this doesn't need a dedicated variable.
>> Try this:
>>
>>
>> - name: plate SamAccountName's
>> set_fact:
>> caughtfish: "{{ chum | json_query('[].SamAccountName') }}"
>>
>>
>>
>>
>> --
>> 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/da6396b6-2768-4644-965f-8d32d0716e45n%40googlegroups.com.
--
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/CAL8fbwMU7FE-gGXGi_NZHWMb8guBpfgUCxdMrTXR19DAbHibCQ%40mail.gmail.com.