小编Mik*_*ike的帖子

Ansible yum update 然后将结果通过电子邮件发送给我

编写剧本以执行 yum 更新,然后从每个服务器获取电子邮件。我希望电子邮件包含yum.log的更改内容。

IOW,我想要以下结果:

grep [today's date] /var/log/yum.log
Run Code Online (Sandbox Code Playgroud)

从每个服务器通过电子邮件发送。

我尝试使用shell:执行 grep 然后发送邮件:

    shell: grep '^`date +"%b %d"`' /var/log/yum.log | mail -s "updates applied to `hostname -s` today" updatereports@mydomain.com
Run Code Online (Sandbox Code Playgroud)

它只是发送一封空白电子邮件。

还尝试使用邮件功能,但我正在努力将多行变量转储到邮件正文中:

- name: test result
  ignore_errors: yes
  shell: grep "`date '+%b %d'`" /var/log/messages
  register: updated

- name: mail result
  mail:
    to: updatereports@mydomain.com
    subject: "updates applied to {{ ansible_hostname }} today"
    body: "{{ item }}"
    with_items: "{{ updated.results|map(attribute='stdout_lines')|list }}"
  when: updated.stdout
Run Code Online (Sandbox Code Playgroud)

它也发送,但打印时间戳,然后为 yum.log 中的每个匹配行生成一行错误:

['Sep 12 16:15:28 host-ng …
Run Code Online (Sandbox Code Playgroud)

email grep yum ansible

3
推荐指数
1
解决办法
5984
查看次数

标签 统计

ansible ×1

email ×1

grep ×1

yum ×1