# using nested items with json\_query?

**URL:** <https://forum.ansible.com/t/using-nested-items-with-json-query/24174>\
**Category:** Ansible Project\
**Created:** [April 8, 2017, 12:05am UTC](https://forum.ansible.com/t/using-nested-items-with-json-query/24174 "2017-04-08T00:05:19Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tom\_Trahan](https://avatars.discourse-cdn.com/v4/letter/t/5fc32e/32.png) [@Tom\_Trahan](https://forum.ansible.com/u/Tom_Trahan)\
**Post date:** [April 8, 2017, 12:05am UTC](https://forum.ansible.com/t/using-nested-items-with-json-query/24174/1 "2017-04-08T00:05:19Z")

</div>

I’m trying to do the following:

- From an object that stores multiple EC2 instance ids
- Use those values to iterate over a second json object using each individual instance id as a filter

I’ve tried to do this with json\_query with multiple approaches, including the following:

> 

> 

> - name: Terminate instances with tag Role = {{ ec2\_tag\_Role }}  
> ec2:  
> region: “{{ ec2\_region }}”  
> instance\_ids: “{{ ec2\_id }}”  
> state: ‘absent’  
> wait: true  
> delegate\_to: “localhost”  
> register: ec2

> - name: Get node information from Shippable  
> uri:  
> url: [https://api.shippable.com/clusterNodes](https://api.shippable.com/clusterNodes)  
> method: GET  
> headers:  
> authorization: “apiToken {{ API\_TOKEN }}”  
> cache-control: “no-cache”  
> content-type: “application/json”  
> register: shippable

> - name: Get clusterNodeIds for Shippable nodes  
> debug: var=item  
> vars:  
> query: “"json[?friendlyName==‘" + item[0] + "’].{id: node}"”  
> with\_nested:
> - “{{ ec2.instances.id }}”
> - “{{ shippable|json\_query(query) }}”  
> register: shippableClusterIds

The above attempt doesn’t work, as the vars: query statement is scoped once, not on each iteration of the nested loop. Is there any way to use the the values from the first item in the nested items inside the json\_query statement? I don’t need to use json\_query if there’s another way to accomplish this.
