# Looping for find results

**URL:** <https://forum.ansible.com/t/looping-for-find-results/25169>\
**Category:** Ansible Project\
**Created:** [August 2, 2017, 9:50pm UTC](https://forum.ansible.com/t/looping-for-find-results/25169 "2017-08-02T21:50:34Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_Bushey](https://avatars.discourse-cdn.com/v4/letter/m/e9bcb4/32.png) [@Michael\_Bushey](https://forum.ansible.com/u/Michael_Bushey)\
**Post date:** [August 2, 2017, 9:50pm UTC](https://forum.ansible.com/t/looping-for-find-results/25169/1 "2017-08-02T21:50:34Z")

</div>

On Ansible 2.3.1.0 this works:

- name: Identify logs  
find: paths=/var/log/nginx patterns=“\*.log”  
ignore\_errors: true  
register: files\_to\_delete

- name: Remove debug file log  
file: path=/tmp/test.log state=absent

- name: Log matched files  
shell: echo {{ item.path }} /tmp \>\> /tmp/test.log  
with\_items: “{{ files\_to\_delete.files }}”

It would be nice to be able to do a debug var or msg, but that seems to break the loop for some reason. Anyway I can dump the matched log files in /tmp/test.log on each server in /tmp/test.log.

I would like to extend the find:

- name: Identify logs  
find: paths=/var/log/{{ item }} patterns=“\*.log”  
with\_items:
- nginx
- apache
- qmail
- opensmtp  
ignore\_errors: true  
register: files\_to\_delete

doing a debug: var=files\_to\_delete I see the following structure:  
ok: [server] =\> {  
“files\_to\_delete”: {  
“changed”: false,  
“msg”: “All items completed”,  
“results”: [  
{  
“\_ansible\_item\_result”: true,  
“\_ansible\_no\_log”: false,  
“\_ansible\_parsed”: true,  
“changed”: false,  
“examined”: 4,  
“files”: [  
{  
“atime”: 1501710174.3968189,  
“ctime”: 1501710167.0451255,  
“dev”: 51713,  
“gid”: 0,  
“inode”: 1307247,  
“isblk”: false,  
“ischr”: false,  
“isdir”: false,  
“isfifo”: false,  
“isgid”: false,  
“islnk”: false,  
“isreg”: true,  
“issock”: false,  
“isuid”: false,  
“mode”: “0644”,  
“mtime”: 1501710167.0451255,  
“nlink”: 1,  
“path”: “/var/logs/qmail/debug.log”,  
…

I tried many things such as:

- name: Log matched files  
shell: echo {{ item.path }} /tmp \>\> /tmp/test.log  
with\_subelements:
- “{{ files\_to\_delete.results }}”
- files

but I am not able to get this to work. I’ve found several blog posts on this but either this version of Ansible is broke in regards to this or the functionality has changed.

Any ideas?

Thanks!  
Michael
