I have a variable named myvar, which is defined as follows
- debug: var=myvar
ok: [127.0.0.1] => {
"myvar": {
"name": "george"
"description": "blah blah"
}
}
I want to search for that variable based on the name attribute. For example, I want to provide the name "george" and retrieve the upper level myvar variable.
- name: search
set_fact:
list_of_matched_vars: "{{ vars | json_query(query) }}"
vars:
query: "[?[].name=='george']"
The above returns an empty result. I need to somehow represent that I want to search for any variable name, which has the attribute "name" matching to the value "george". In fact I want to search for a list of matching values, like "george, helen", however, I guess this would be even trickier so lets take the simpler case first.
How can I search for the above myvar variable based on it's 'name' attribute?