# mail multi-line format

**URL:** <https://forum.ansible.com/t/mail-multi-line-format/38153>\
**Category:** Ansible Project\
**Created:** [June 23, 2023, 4:40pm UTC](https://forum.ansible.com/t/mail-multi-line-format/38153 "2023-06-23T16:40:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dbs34](https://avatars.discourse-cdn.com/v4/letter/d/8dc957/32.png) [@dbs34](https://forum.ansible.com/u/dbs34)\
**Post date:** [June 23, 2023, 4:40pm UTC](https://forum.ansible.com/t/mail-multi-line-format/38153/1 "2023-06-23T16:40:48Z")

</div>

Hello!

I have tried various ways to get my output to email in a readable format, with newlines, but ansible strips them off everytime. Its just a few shell commands i am testing. I’ve tried a for loop, with items, replace, etc. My email output is all on one-line like so:

"- ’ 12:23:27 up 64 days, 1:36, 2 users, load average: 0.21, 0.08, 0.02’ - USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT - ‘dbsxxx pts/0 ho-it-dbsxxx-dt Tue08 19:39m 0.16s 0.30s sshd: dbsxxxx [priv]’ - root pts/1 ho-lx-ansible01. 12:23 0.00s 0.10s 0.00s /usr/bin/w - Filesystem Size Used Avail Use% Mounted on - devtmpfs 11G 0 11G 0% /dev - tmpfs 11G 0 11G 0% /dev/shm - tmpfs 11G 1.1G 9.1G 11% /run - tmpfs 11G 0 11G 0% /sys/fs/cgroup - /dev/mapper/rootvg-root 46G 28G 19G 61% / - /dev/mapper/rootvg-home 10G 33M 10G 1% /home - /dev/sda1 1.1G 383M 656M 37% /boot - /dev/mapper/satvg-satlv01 503G 408G 96G 82% /var/satellite - /dev/mapper/oravg-oralv01 142G 41G 102G 29% /opt/oracle - tmpfs 2.1G 0 2.1G 0% /run/user/0 - tmpfs 2.1G 0 2.1G 0% /run/user/1922732921 "

my yaml code is:

- name: DF + UPTIME PLAYBOOK  
hosts: “\*”  
gather\_facts: false

tasks:

- shell: |  
/usr/bin/w  
/usr/bin/df -h  
register: dfu

- debug: var=dfu.stdout\_lines

- name: mail result  
community.general.mail:  
sender: [ro...@ho-lx-ansible.xxxxxx.com](mailto:ro...@ho-lx-ansible.xxxxxx.com)  
host: [internal-smtp.xxxxxx.com](http://internal-smtp.xxxxxx.com)  
subtype: html  
body: 

How do I tell ansible to output in a email format like the way I see it from the debug output on my screen?

ok: [ho-lx-sys-olm01] =\>  
dfu.stdout\_lines:

- ’ 12:23:27 up 64 days, 1:36, 2 users, load average: 0.21, 0.08, 0.02’
- USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
- ‘dbxxxx pts/0 ho-it-dbxxx-dt Tue08 19:39m 0.16s 0.30s sshd: dbsxxx [priv]’
- root pts/1 ho-lx-ansible01. 12:23 0.00s 0.10s 0.00s /usr/bin/w
- Filesystem Size Used Avail Use% Mounted on
- devtmpfs 11G 0 11G 0% /dev
- tmpfs 11G 0 11G 0% /dev/shm
- tmpfs 11G 1.1G 9.1G 11% /run
- tmpfs 11G 0 11G 0% /sys/fs/cgroup
- /dev/mapper/rootvg-root 46G 28G 19G 61% /
- /dev/mapper/rootvg-home 10G 33M 10G 1% /home
- /dev/sda1 1.1G 383M 656M 37% /boot
- /dev/mapper/satvg-satlv01 503G 408G 96G 82% /var/satellite
- /dev/mapper/oravg-oralv01 142G 41G 102G 29% /opt/oracle
- tmpfs 2.1G 0 2.1G 0% /run/user/0
- tmpfs 2.1G 0 2.1G 0% /run/user/1922732921

thank you!

---

<div class="post-metadata">

**Author:** ![dnmvisser](https://avatars.discourse-cdn.com/v4/letter/d/8e8cbc/32.png) [@dnmvisser](https://forum.ansible.com/u/dnmvisser)\
**Post date:** [June 23, 2023, 5:32pm UTC](https://forum.ansible.com/t/mail-multi-line-format/38153/2 "2023-06-23T17:32:06Z")

</div>

> Hello!
> 
> I have tried various ways to get my output to email in a readable format, with newlines, but ansible strips them off everytime. Its just a few shell commands i am testing. I’ve tried a for loop, with items, replace, etc. My email output is all on one-line like so:
> 
> "- ’ 12:23:27 up 64 days, 1:36, 2 users, load average: 0.21, 0.08, 0.02’ - USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT - ‘dbsxxx pts/0 ho-it-dbsxxx-dt Tue08 19:39m 0.16s 0.30s sshd: dbsxxxx [priv]’ - root pts/1 ho-lx-ansible01. 12:23 0.00s 0.10s 0.00s /usr/bin/w - Filesystem Size Used Avail Use% Mounted on - devtmpfs 11G 0 11G 0% /dev - tmpfs 11G 0 11G 0% /dev/shm - tmpfs 11G 1.1G 9.1G 11% /run - tmpfs 11G 0 11G 0% /sys/fs/cgroup - /dev/mapper/rootvg-root 46G 28G 19G 61% / - /dev/mapper/rootvg-home 10G 33M 10G 1% /home - /dev/sda1 1.1G 383M 656M 37% /boot - /dev/mapper/satvg-satlv01 503G 408G 96G 82% /var/satellite - /dev/mapper/oravg-oralv01 142G 41G 102G 29% /opt/oracle - tmpfs 2.1G 0 2.1G 0% /run/user/0 - tmpfs 2.1G 0 2.1G 0% /run/user/1922732921 "
> 
> my yaml code is:
> 
> - name: DF + UPTIME PLAYBOOK  
> hosts: “\*”  
> gather\_facts: false
> 
> tasks:
> 
> - shell: |  
> /usr/bin/w  
> /usr/bin/df -h  
> register: dfu
> 
> - debug: var=dfu.stdout\_lines
> 
> - name: mail result  
> community.general.mail:  
> sender: [ro…@ho-lx-ansible.xxxxxx.com](mailto:ro...@ho-lx-ansible.xxxxxx.com)  
> host: [internal-smtp.xxxxxx.com](http://internal-smtp.xxxxxx.com)  
> subtype: html  
> to: ‘[dbs…@xxxxxx.com](mailto:dbs...@xxxxxx.com)’  
> subject: test  
> body: 
> 
> How do I tell ansible to output in a email format like the way I see it from the debug output on my screen?

The console is using a fixed width font, while your mail client is not.  
You need to format the email body in a way that your mail client uses a fixed width font to display it. This is not something this list is for, but as a start wrap the output in

```
tags instead of
### . Google for email formatting and html to tweak things further.
```

---

<div class="post-metadata">

**Author:** ![dbs34](https://avatars.discourse-cdn.com/v4/letter/d/8dc957/32.png) [@dbs34](https://forum.ansible.com/u/dbs34)\
**Post date:** [June 23, 2023, 5:57pm UTC](https://forum.ansible.com/t/mail-multi-line-format/38153/3 "2023-06-23T17:57:37Z")

</div>

ok thank you Dick, I follow you. Anyway, this is what I came up with and it worked like a charm.
