我想用一些更好的格式在这里漂亮地打印电子邮件正文的输出。
- name: Email notification with better output format
mail:
host: localhost
port: 25
from: user@test.com
to: user1@test.com
subject: TEST
body:
Hostname: {{ value1 }}
IP: {{ value2 }}
delegate_to: localhost
只是想知道是否有一些原生的方式可以很好地打印电子邮件正文内容。目前,我收到的电子邮件正文格式如下:
Hostname:test1
IP:0.3.100.1
我想要一个格式更好的电子邮件正文输出,类似于:
Hostname: test1
IP : 0.3.100.1
谢谢。
使用格式和缩进。例如
- debug:
msg: "{{ body|indent(width=6, first=true, blank=false) }}"
vars:
value1: test1
value2: 0.3.100.1
body: |
{{ "Hostname: %s"|format(value1) }}
{{ "IP : %s"|format(value2) }}
给出
msg: |2-
Hostname: test1
IP : 0.3.100.1