# \[find module\]\[mail module\] Report only file name list

**URL:** <https://forum.ansible.com/t/find-module-mail-module-report-only-file-name-list/31203>\
**Category:** Ansible Project\
**Created:** [September 5, 2019, 7:21am UTC](https://forum.ansible.com/t/find-module-mail-module-report-only-file-name-list/31203 "2019-09-05T07:21:18Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tran\_Khang](https://avatars.discourse-cdn.com/v4/letter/t/bbce88/32.png) [@Tran\_Khang](https://forum.ansible.com/u/Tran_Khang)\
**Post date:** [September 5, 2019, 7:21am UTC](https://forum.ansible.com/t/find-module-mail-module-report-only-file-name-list/31203/1 "2019-09-05T07:21:18Z")

</div>

Hi all,

I’m trying combine find module and mail module to report to my email only the list of files I need that were finded in specific folder. I try many ways but always receive full output. Do anyone can help?

**My tasks**

> * * *
> 
> - name: check if tar files exists  
> find:  
> paths: “{{ bkPath }}”  
> patterns: ‘\*.tar’  
> register: backup\_existed
> 
> - name: results output  
> debug:  
> msg: “{{ item.path }}”  
> with\_items: “{{ backup\_existed.files }}”  
> register: backup\_output
> 
> - name: Report through email  
> mail:  
> host: [smtp.gmail.com](http://smtp.gmail.com)  
> port: 587  
> username: [my\_gmail@gmail.com](mailto:my_gmail@gmail.com)  
> password: SecretPass  
> to: Khang Tran [my\_working@email](mailto:my_working@email)  
> subject: Ansible-Backup-Report  
> body: \>  
> Backup files list:
> 
> - {{ backup\_output }}  
> charset: utf-8  
> delegate\_to: localhost

**Actually Email report:**

> Backup files list: - {‘msg’: u’/20190625/AS/mcpAcct.2019\_06\_25.16\_46\_45.tar’, ‘\_ansible\_verbose\_always’: True, ‘\_ansible\_ignore\_errors’: True, ‘\_ansible\_item\_label’: {u’uid’: 1003, u’woth’: False, u’mtime’: 1561456341.9453063, u’inode’: 596799269, u’isgid’: False, u’size’: 3205120, u’roth’: True, u’isuid’: False, u’isreg’: True, u’pw\_name’: u’labbackup’, u’gid’: 1003, 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’labbackup’, u’path’: u’/20190625/AS/mcpAcct.2019\_06\_25.16\_46\_45.tar’, u’xusr’: False, u’atime’: 1561456341.6703176, u’isdir’: False, u’ctime’: 1561456341.9453063, u’isblk’: False, u’xgrp’: False, u’dev’: 64770, u’wgrp’: True, u’isfifo’: False, u’mode’: u’0664’, u’islnk’: False}}, {‘changed’: False, ‘\_ansible\_no\_log’: False, ‘item’: {u’uid’: 1003, u’woth’: False, u’mtime’: 1561456341.951306, u’inode’: 596799270, u’isgid’: False, u’size’: 40960, u’roth’: True, u’isuid’: False, u’isreg’: True, u’pw\_name’: u’labbackup’, u’gid’: 1003, 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’labbackup’, u’path’: u’/20190625/AS/mcpAcct.2019\_06\_25.16\_51\_33.tar’, u’xusr’: False, u’atime’: 1561456341.9463062, u’isdir’: False, u’ctime’: 1561456341.951306, u’wgrp’: True, u’xgrp’: False, u’dev’: 64770, u’isblk’: False, u’isfifo’: False, u’mode’: u’0664’, u’islnk’: False}, ‘\_ansible\_item\_result’: True, ‘failed’: False }

**Expected Email report contain:**

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [September 5, 2019, 7:59am UTC](https://forum.ansible.com/t/find-module-mail-module-report-only-file-name-list/31203/2 "2019-09-05T07:59:31Z")

</div>

Skip the debug task, and use backup\_existed in your mail task.  
You do have to filter that down to a list of files, and then iterate  
over that in jinja in the body parameter.

---

<div class="post-metadata">

**Author:** ![Tran\_Khang](https://avatars.discourse-cdn.com/v4/letter/t/bbce88/32.png) [@Tran\_Khang](https://forum.ansible.com/u/Tran_Khang)\
**Post date:** [September 5, 2019, 8:27am UTC](https://forum.ansible.com/t/find-module-mail-module-report-only-file-name-list/31203/3 "2019-09-05T08:27:10Z")

</div>

Hi Visser,

I’m an ansible newbie, could you please help me in detail how to filter down and iterate in jinja in body parameter?

Regards,

Khang Tran

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [September 5, 2019, 9:12am UTC](https://forum.ansible.com/t/find-module-mail-module-report-only-file-name-list/31203/4 "2019-09-05T09:12:27Z")

</div>

Remove the debug task.  
And use this in the mail task:

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;body: \>  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Backup list  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{% for file in backup\_existed.files %}  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- {{ file.path }}  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{% endfor %}

You might need to tweak the newlines and formatting a bit.

Dick

---

<div class="post-metadata">

**Author:** ![Tran\_Khang](https://avatars.discourse-cdn.com/v4/letter/t/bbce88/32.png) [@Tran\_Khang](https://forum.ansible.com/u/Tran_Khang)\
**Post date:** [September 5, 2019, 9:22am UTC](https://forum.ansible.com/t/find-module-mail-module-report-only-file-name-list/31203/5 "2019-09-05T09:22:16Z")

</div>

Thanks Visser a lots, it works exactly as expected.
