Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux ansible playbook/shell命令的电子邮件结果?_Linux_Ansible - Fatal编程技术网

Linux ansible playbook/shell命令的电子邮件结果?

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"

我希望通过电子邮件发送ansible剧本的结果

我正在使用debug:var=results.stdout_行来显示shell命令的stdout,但我想将其打包并通过电子邮件发送给我自己

我觉得必须有一个内置的方式来做这件事,但我找不到任何东西

我的剧本看起来像

- 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