I have the following structure.
[
{
"ami_launch_index": 0,
"architecture": "x86_64",
"instance_type": "t2.micro",
"monitoring": {
"state": "disabled"
} ,
"placement": {
"availability_zone": "eu-central-1a",
"group_name": "",
"tenancy": "default"
},
"tags": {
"Name": "MYNAME 1",
"Project": "MY PROJECT",
"Purpose": "MYTEST"
},
"virtualization_type": "hvm"
},
{
"ami_launch_index": 2,
"architecture": "x86_64",
"instance_type": "t2.micro",
"monitoring": {
"state": "disabled"
},
"placement": {
"availability_zone": "eu-central-1a",
"group_name": "",
"tenancy": "default"
},
"tags": {
"Name": "MYNAME 2",
"Project": "MY SECOND PROJECT",
"Purpose": "WHY THE HECK NOT"
},
"virtualization_type": "hvm"
}
]
I want to print all elements where [].tags.Name contains the string "SECOND" (so just the second element. How do I achieve this?
This is what I've tried, but it's not working.
- debug:
msg: "{{ instances.stdout | from_json | json_query(\"[][?contains(tags.Name, 'SECOND')]\") }}"
I tried using http://jmespath.org but can't extract the data the way I want either.