# Ansible output from csv file to html table

**URL:** <https://forum.ansible.com/t/ansible-output-from-csv-file-to-html-table/28425>\
**Category:** Ansible Project\
**Created:** [August 27, 2018, 3:27am UTC](https://forum.ansible.com/t/ansible-output-from-csv-file-to-html-table/28425 "2018-08-27T03:27:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Saravanan](https://avatars.discourse-cdn.com/v4/letter/s/eb8c5e/32.png) [@Saravanan](https://forum.ansible.com/u/Saravanan)\
**Post date:** [August 27, 2018, 3:27am UTC](https://forum.ansible.com/t/ansible-output-from-csv-file-to-html-table/28425/1 "2018-08-27T03:27:30Z")

</div>

All,  
Ansible output of a playbook is csv file format. This needs to be converted to html table and send as mail body output within Ansible playbook.  
Can someone share the task detail to convert csv file to html table.

---

<div class="post-metadata">

**Author:** ![Saravanan](https://avatars.discourse-cdn.com/v4/letter/s/eb8c5e/32.png) [@Saravanan](https://forum.ansible.com/u/Saravanan)\
**Post date:** [August 27, 2018, 11:40am UTC](https://forum.ansible.com/t/ansible-output-from-csv-file-to-html-table/28425/2 "2018-08-27T11:40:48Z")

</div>

All,  
In the below Ansible email task, instead of attaching the csv file to the email, need to send the contend of csv file in the body of the email as html table.

`

- name: Send the SSH status to email  
local\_action: mail  
host= ‘127.0.0.1’  
port=25  
subject=“SSH Connection status for Unix sudo accounts”  
body=“SSH Failure Service accounts”  
attach=“/tmp/content.csv”  
from=“[admin@localhost.com](mailto:admin@localhost.com)”  
to=“someone[@email.com](mailto:Saravanan.Ponnusamy@email.com)”  
subtype=“html”  
charset=utf8  
delegate\_to: 127.0.0.1  
run\_once: true  
`

---

<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:** [August 27, 2018, 2:56pm UTC](https://forum.ansible.com/t/ansible-output-from-csv-file-to-html-table/28425/3 "2018-08-27T14:56:20Z")

</div>

> All,  
> In the below Ansible email task, instead of attaching the csv file to the  
> email, need to send the contend of csv file in the body of the email as  
> html table.

I'm not sure what you are trying too achieve but you should probably check at ARA [https://github.com/openstack/ara](https://github.com/openstack/ara)

> &nbsp;&nbsp;&nbsp;- name: Send the SSH status to email  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;local\_action: mail  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;host= '127.0.0.1'  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;port=25  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;subject="SSH Connection status for Unix sudo accounts"  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;body="SSH Failure Service accounts"  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;attach="/tmp/content.csv"  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from="admin@localhost.com"  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;to="someone@email.com \<Saravanan.Ponnusamy@email.com\>"  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;subtype="html"  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;charset=utf8  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;delegate\_to: 127.0.0.1  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;run\_once: true

What you are trying to do is possible but you need to go through a lot of hoops, choosing csv is making this harder that is could be, yaml or json would have been easier.

As is, you would need to create the csv file to a list of list, then use template to create the html table.

---

<div class="post-metadata">

**Author:** ![Saravanan](https://avatars.discourse-cdn.com/v4/letter/s/eb8c5e/32.png) [@Saravanan](https://forum.ansible.com/u/Saravanan)\
**Post date:** [September 4, 2018, 4:41pm UTC](https://forum.ansible.com/t/ansible-output-from-csv-file-to-html-table/28425/4 "2018-09-04T16:41:48Z")

</div>

Kai,  
Here is my actual playbook. This gives me the output in plain csv file format. To represent the output via email, please suggest the right approach.
