# How do I refer to the previously defined variable in "with\_nested"?

**URL:** <https://forum.ansible.com/t/how-do-i-refer-to-the-previously-defined-variable-in-with-nested/13735>\
**Category:** Ansible Project\
**Created:** [October 21, 2013, 6:04pm UTC](https://forum.ansible.com/t/how-do-i-refer-to-the-previously-defined-variable-in-with-nested/13735 "2013-10-21T18:04:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dan\_J](https://avatars.discourse-cdn.com/v4/letter/d/f19dbf/32.png) [@Dan\_J](https://forum.ansible.com/u/Dan_J)\
**Post date:** [October 21, 2013, 6:04pm UTC](https://forum.ansible.com/t/how-do-i-refer-to-the-previously-defined-variable-in-with-nested/13735/1 "2013-10-21T18:04:07Z")

</div>

For example, I would like to do something like this:

- name: install git repos for all users  
git: “repo={{ item[1].repo }} dest={{ item[0].home }}/{{ item[1].dest }}”  
with\_nested:
- users
- item[0][‘repos’][‘git’]

---

<div class="post-metadata">

**Author:** ![Serge\_van\_Ginderacht](https://avatars.discourse-cdn.com/v4/letter/s/b782af/32.png) [@Serge\_van\_Ginderacht](https://forum.ansible.com/u/Serge_van_Ginderacht)\
**Post date:** [October 21, 2013, 6:17pm UTC](https://forum.ansible.com/t/how-do-i-refer-to-the-previously-defined-variable-in-with-nested/13735/2 "2013-10-21T18:17:36Z")

</div>

I \*think\* you want the with\_subelement lookup plugin.

see  
[http://www.ansibleworks.com/docs/playbooks\_loops.html#looping-over-subelements](http://www.ansibleworks.com/docs/playbooks_loops.html#looping-over-subelements)  
other example also via [https://github.com/ansible/ansible/pull/4071​​](https://github.com/ansible/ansible/pull/4071%E2%80%8B%E2%80%8B)
