如何使用Ansible发送电子邮件

jgg*_*jgg 6 email yaml ansible ansible-playbook

我正在尝试使用Ansible发送电子邮件,但我无法理解它是如何工作的,因为我不知道如何为此类服务提供用户和密码(未在文档中指定).

我的机器和电子邮件服务器都在同一个网络中,但我需要通过身份验证才能发送电子邮件.

这是我的yml文件:

--- 
- name: Testing email
  hosts: localhost
  tasks: 
    - name: Send email
      local_action: mail
        host=mail.server.com
        port=993
        subject="Ansible test mail"
        body="Testing email"
        from=my@email
        to="y@email
        charset=utf8
Run Code Online (Sandbox Code Playgroud)

这是主机文件的相关内容:

[localhost]
localhost ansible_connection=local
Run Code Online (Sandbox Code Playgroud)

有关如何配置它的任何想法?提前致谢.

Woo*_*ham 5

查看该mail模块的源代码(https://github.com/ansible/ansible/blob/d1effecb2ef073e478c67a7ca39cf56708a66a48/library/notification/mail),它看起来不支持SMTP身份验证.

但是,添加对它的支持应该不会太难.它需要将用户名和密码参数添加到模块中,检测它们是否已经提供,如果是,则smtp.login()使用这些参数进行调用.

实际上,看起来目前有两个拉动请求可以完成

https://github.com/ansible/ansible/pull/7213

和这里

https://github.com/ansible/ansible/pull/6667

所以支持很可能很快会在开发中添加.