# Find module results not returning as expected

**URL:** <https://forum.ansible.com/t/find-module-results-not-returning-as-expected/27220>\
**Category:** Ansible Project\
**Tags:** ansible-project\
**Created:** [April 8, 2018, 7:58pm UTC](https://forum.ansible.com/t/find-module-results-not-returning-as-expected/27220 "2018-04-08T19:58:50Z")\
**Posts on this page:** 1\
**Page:** 1

<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:** [April 8, 2018, 7:58pm UTC](https://forum.ansible.com/t/find-module-results-not-returning-as-expected/27220/1 "2018-04-08T19:58:50Z")

</div>

> Using the find module to find unknown files in a given directory and  
> register the results as a variable to be looped through later on. The debug  
> of the registered var shows a full on array of all kinds of attributes  
> about the files (way more than I want) - except the file name! It does show  
> the file name in the files.path, which I should be able to filter with  
> basename, but that doesn't work either. This either should be much more  
> straightforward, or my understanding of this is way off.
> 
> Question: How do I store unknown file names in a dir as a list that I can  
> loop through in a subsequent task?
> 
> My current play (I've tried a few different iterations - and the echo is  
> just an example, would like to do other things like use the script module  
> and such):
> 
> ---  
> - hosts: localhost  
> &nbsp;&nbsp;&nbsp;tasks:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- name: Check the files  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;find:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;paths: /home/gforster/projects/scripts  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;register: files\_found
> 
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- name: echo files  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;command: "echo {{ item.path | basename }}"  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;loop: "{{ files\_found.files }}"

It's nothing wrong with this.

> Expected Results:
> 
> TASK [echo files]  
> \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
> changed: [localhost] =\> {  
> &nbsp;&nbsp;&nbsp;&nbsp;"msg": "some\_filesname"  
> }

If you looking for something like this you need to use the debug instead of command module.

&nbsp;&nbsp;&nbsp;&nbsp;- name: echo files  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;debug: msg="{{ item.path | basename }}"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;loop: "{{ files\_found.files }}"

> Actual Results:  
> TASK [echo files]  
> \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
> changed: [localhost] =\> (item={u'uid': 1000, u'woth': True, u'mtime':  
> 1522857501.1654217, u'inode': 20547673299942532, u'isgid': False, u'size':  
> 359, u'roth': True, u'isuid': False, u'isreg': True, u'pw\_name': u'gforster'  
> , u'gid': 1000, u'ischr': False, u'wusr': True, u'xoth': False, u'rusr':  
> True, u'nlink': 1, u'issock': False, u'rgrp': True, u'gr\_name': u'gforster',  
> u'path': u'/home/gforster/projects/scripts/101\_names', u'xusr': False, u  
> 'atime': 1522857501.1649039, u'isdir': False, u'ctime': 1522857501.1654217,  
> u'wgrp': True, u'xgrp': False, u'dev': 2, u'isblk': False, u'isfifo': False,  
> u'mode': u'0666', u'islnk': False})  
> changed: [localhost] =\> (item={u'uid': 1000, u'woth': True, u'mtime':  
> 1522857463.1172974, u'inode': 9570149208257507, u'isgid': False, u'size':  
> 1261, u'roth': True, u'isuid': False, u'isreg': True, u'pw\_name': u  
> 'gforster', u'gid': 1000, u'ischr': False, u'wusr': True, u'xoth': False, u  
> 'rusr': True, u'nlink': 1, u'issock': False, u'rgrp': True, u'gr\_name': u  
> 'gforster', u'path': u'/home/gforster/projects/scripts/101\_to\_masterfile', u  
> 'xusr': False, u'atime': 1522857457.6757936, u'isdir': False, u'ctime':  
> 1522857463.1829827, u'wgrp': True, u'xgrp': False, u'dev': 2, u'isblk':  
> False, u'isfifo': False, u'mode': u'0666', u'islnk': False})

You output is missing a lot of things, are you sure that you copied all?
