# Display file content in body of mail module

**URL:** <https://forum.ansible.com/t/display-file-content-in-body-of-mail-module/33620>\
**Category:** Ansible Project\
**Created:** [August 15, 2020, 5:24am UTC](https://forum.ansible.com/t/display-file-content-in-body-of-mail-module/33620 "2020-08-15T05:24:30Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sivaraman\_P](https://avatars.discourse-cdn.com/v4/letter/s/b77776/32.png) [@Sivaraman\_P](https://forum.ansible.com/u/Sivaraman_P)\
**Post date:** [August 15, 2020, 5:24am UTC](https://forum.ansible.com/t/display-file-content-in-body-of-mail-module/33620/1 "2020-08-15T05:24:30Z")

</div>

Hi All,

How to display the file contents in the body of the mail module.

mail:  
&nbsp;&nbsp;body: /tmp/file2.txt

---

<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:** [August 15, 2020, 6:34am UTC](https://forum.ansible.com/t/display-file-content-in-body-of-mail-module/33620/2 "2020-08-15T06:34:19Z")

</div>

cat /tmp/file2.txt

---

<div class="post-metadata">

**Author:** ![Sivaraman\_P](https://avatars.discourse-cdn.com/v4/letter/s/b77776/32.png) [@Sivaraman\_P](https://forum.ansible.com/u/Sivaraman_P)\
**Post date:** [August 15, 2020, 9:29am UTC](https://forum.ansible.com/t/display-file-content-in-body-of-mail-module/33620/3 "2020-08-15T09:29:41Z")

</div>

I have used the below playbook and the lookup option getting failed

- name:send mail  
&nbsp;&nbsp;mail:  
&nbsp;&nbsp;&nbsp;&nbsp;subtype: html

---

<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:** [August 15, 2020, 9:39am UTC](https://forum.ansible.com/t/display-file-content-in-body-of-mail-module/33620/4 "2020-08-15T09:39:34Z")

</div>

> I have used the below playbook and the lookup option getting failed
> 
> - name:send mail  
> &nbsp;&nbsp;mail:  
> &nbsp;&nbsp;&nbsp;&nbsp;subtype: html  
> &nbsp;&nbsp;&nbsp;&nbsp;to: xxx.gmail.com  
> &nbsp;&nbsp;&nbsp;&nbsp;from: yyy.gmail.com  
> &nbsp;&nbsp;&nbsp;&nbsp;subject: test email  
> &nbsp;&nbsp;&nbsp;&nbsp;body: "{{lookup('file', '/tmp/{{today}}.html')}}"

(This line ^^ is distinctly different from your initial message BTW)

In any case, you can't use nested jinja delimiters ({{}}).  
Try this:

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;body: "{{ lookup('file', '/tmp/' ~ today ~ '.html') }}"

---

<div class="post-metadata">

**Author:** ![Sivaraman\_P](https://avatars.discourse-cdn.com/v4/letter/s/b77776/32.png) [@Sivaraman\_P](https://forum.ansible.com/u/Sivaraman_P)\
**Post date:** [August 15, 2020, 10:20am UTC](https://forum.ansible.com/t/display-file-content-in-body-of-mail-module/33620/5 "2020-08-15T10:20:18Z")

</div>

Getting the same error.

---

<div class="post-metadata">

**Author:** ![Sivaraman\_P](https://avatars.discourse-cdn.com/v4/letter/s/b77776/32.png) [@Sivaraman\_P](https://forum.ansible.com/u/Sivaraman_P)\
**Post date:** [August 15, 2020, 10:33am UTC](https://forum.ansible.com/t/display-file-content-in-body-of-mail-module/33620/6 "2020-08-15T10:33:08Z")

</div>

The file is present in the target machine. whether lookup will not work there.

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [August 15, 2020, 10:58am UTC](https://forum.ansible.com/t/display-file-content-in-body-of-mail-module/33620/7 "2020-08-15T10:58:21Z")

</div>

Lookups are always done on the controller. You could retrieve the file from the  
target machine with the "fetch" module.

Regards  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Racke
