# Parsing var created with loop

**URL:** <https://forum.ansible.com/t/parsing-var-created-with-loop/26828>\
**Category:** Ansible Project\
**Created:** [February 22, 2018, 9:26pm UTC](https://forum.ansible.com/t/parsing-var-created-with-loop/26828 "2018-02-22T21:26:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![John\_Harmon](https://avatars.discourse-cdn.com/v4/letter/j/edb3f5/32.png) [@John\_Harmon](https://forum.ansible.com/u/John_Harmon)\
**Post date:** [February 22, 2018, 9:26pm UTC](https://forum.ansible.com/t/parsing-var-created-with-loop/26828/1 "2018-02-22T21:26:01Z")

</div>

I have the following output from a variable called directories. It was created using a loop that would run stat against two different paths. What is the proper way to reference the “stat: exists: boolean” sections of the output? I need to check for both directories for both item.paths. I have tried and tried, but I must be doing something wrong.

`"directories.results": [{ "_ansible_ignore_errors": null, "_ansible_item_result": true, "_ansible_no_log": false, "_ansible_parsed": true, "changed": false, "failed": false, "invocation": { "module_args": { "checksum_algorithm": "sha1", "follow": false, "get_attributes": true, "get_checksum": true, "get_md5": true, "get_mime": true, "path": "/home/applmgr/Scripts" } }, **"item": {**  **"path": "/home/applmgr/Scripts"** }, "stat": { "atime": 1519330068.2478893, "attr_flags": "e", "attributes": [ "extents"], ......lots of stuff **"exists": true,** `…lots of stuff`  
}  
},  
{  
“\_ansible\_ignore\_errors”: null,  
“\_ansible\_item\_result”: true,  
“\_ansible\_no\_log”: false,  
“\_ansible\_parsed”: true,  
“changed”: false,  
“failed”: false,  
“invocation”: {  
“module\_args”: {  
“checksum\_algorithm”: “sha1”,  
“follow”: false,  
“get\_attributes”: true,  
“get\_checksum”: true,  
“get\_md5”: true,  
“get\_mime”: true,  
“path”: “/home/oracle/Scripts”  
}  
},  
**“item”: {**  
**“path”: “/home/oracle/Scripts”**  
**},**  
**“stat”: {**  
**“exists”: false**  
}  
}  
]  
}

`

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [February 22, 2018, 9:57pm UTC](https://forum.ansible.com/t/parsing-var-created-with-loop/26828/2 "2018-02-22T21:57:28Z")

</div>

It depends on what you want to do next.  
The fist one is  
&nbsp;&nbsp;{{ directories.results.0.stats.exists }}  
and the second one is  
&nbsp;&nbsp;{{ directories.results.1.stats.exists }}

If you need both to be true before running a task that would be

&nbsp;&nbsp;when: directories.results.0.stats.exists and directories.results.1.stats.exists

since they are bools.

---

<div class="post-metadata">

**Author:** ![John\_Harmon](https://avatars.discourse-cdn.com/v4/letter/j/edb3f5/32.png) [@John\_Harmon](https://forum.ansible.com/u/John_Harmon)\
**Post date:** [February 22, 2018, 10:03pm UTC](https://forum.ansible.com/t/parsing-var-created-with-loop/26828/3 "2018-02-22T22:03:43Z")

</div>

Thanks Kai. I still see a problem:

`

- name: debug  
debug:  
var: directories.results.0.stats.exists

Result:  
TASK [debug] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [labebs-apps1] =\> {  
“directories.results.0.stats.exists”: “VARIABLE IS NOT DEFINED!”  
}

`

Is there any way to reference it by something more descriptive, like a name?

---

<div class="post-metadata">

**Author:** ![John\_Harmon](https://avatars.discourse-cdn.com/v4/letter/j/edb3f5/32.png) [@John\_Harmon](https://forum.ansible.com/u/John_Harmon)\
**Post date:** [February 22, 2018, 10:07pm UTC](https://forum.ansible.com/t/parsing-var-created-with-loop/26828/4 "2018-02-22T22:07:59Z")

</div>

Sorry, syntax error. Had stats not stat.
