Linux ansible playbook/shell命令的电子邮件结果?
我希望通过电子邮件发送ansible剧本的结果 我正在使用debug:var=results.stdout_行来显示shell命令的stdout,但我想将其打包并通过电子邮件发送给我自己 我觉得必须有一个内置的方式来做这件事,但我找不到任何东西 我的剧本看起来像Linux ansible playbook/shell命令的电子邮件结果?,linux,ansible,Linux,Ansible,我希望通过电子邮件发送ansible剧本的结果 我正在使用debug:var=results.stdout_行来显示shell命令的stdout,但我想将其打包并通过电子邮件发送给我自己 我觉得必须有一个内置的方式来做这件事,但我找不到任何东西 我的剧本看起来像 - name: run command shell: echo `hostname` register: results when: ansible_os_family == "Debian"
- name: run command
shell: echo `hostname`
register: results
when: ansible_os_family == "Debian"
- debug: var=results.stdout_lines
它将在playbook运行期间打印命令的stdout结果,但我想随后通过电子邮件将其发送给我自己
我试图通过电子邮件发送注册变量“results”,但失败了
- local_action: mail
subject='Maricache backup report'
body={{ results.stdout_lines }}
to='partytime@gmail.com'
尝试一下,在某个地方找到了解决方案,它对我也很有效
- name: logs result
shell: grep "`date '+%b.%d'`" /var/log/commands.log
register: command_log
- name: mail result
mail:
to: helloworld@xyz.com
subject: "command logs for today"
body: "{{ command_log.stdout }}"
when: command_log.stdout