6

我正在尝试使用 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

这是hosts文件的相关内容:

[localhost]
localhost ansible_connection=local

关于我应该如何配置它的任何想法?提前致谢。

4

1 回答 1

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

因此,很可能很快就会在开发中添加支持。

于 2014-07-02T12:01:22.603 回答