I have a JSON blob from Amazon's AWS describing a whole lot of load balancers. I would like to extract the names of all the load balancers on a certain subnet. I use Ansible so the language of choice for selecting bits of JSON is JmesPath. Do you know how to do this?
Here is the structure of the JSON blob and my attempt so far:
The data:
{
"LoadBalancerDescriptions": [
{
"want": "Yes!",
"Subnets": ["subnet-123456"],
"LoadBalancerName": "foo"
},
{
"want": "Yes!",
"Subnets": ["subnet-9876","subnet-123456"],
"LoadBalancerName": "bar"
},
{
"want": "No.",
"Subnets": ["subnet-123456"],
"LoadBalancerName": "batmobile"
}
]
}
Attempt:
Here I am using the golang command line Jmespath client; the same expressions should work in Ansible:
cat ,elb--describe-load-balancers.json |\
jmespath "LoadBalancerDescriptions[?Subnets[?@='subnet-123456']].LoadBalancerName" |\
wc -l