On Fri, 23 Jun 2023 at 18:40, dbs34 <[email protected]> wrote:
> 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: [email protected] > host: internal-smtp.xxxxxx.com > subtype: html > to: '[email protected]' > subject: test > body: <h3> "{{ dfu.stdout_lines | to_nice_yaml(indent=4) }}" </h3> > ... > > 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 <pre> tags instead of <h3>. Google for email formatting and html to tweak things further. > > 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! > > -- > You received this message because you are subscribed to the Google Groups > "Ansible Project" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/ansible-project/55dbf7bc-2383-47ad-bd17-1debbd9e683an%40googlegroups.com > <https://groups.google.com/d/msgid/ansible-project/55dbf7bc-2383-47ad-bd17-1debbd9e683an%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- Sent from Gmail Mobile -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAF8BbLbDmRoNoc%3D1Xir65n3t3VEtamavJDqqrNbJni2dvL7F9Q%40mail.gmail.com.
