首页 » 翻译 » Ansible » 正文

ansible 邮件通知

有事后,我们可能想通过邮件来接收一些通知,例如:

我们每隔3个小时会自动跑一遍Playbook来确保HTTP处于运行状态,如果HTTP不处于运行状态,我们希望ansible帮我启动它,并发邮件通知我(这不是ansible的常规用法,非战斗人员请紧急撤离,一般这种监控都是分钟级别的,不可能存在HTTP挂了30分钟的情况)

这个时候我们如果想发邮件,就必须用到ansible 的 mail 模块:

例子如下:

具体的官方文档参数

parameter required default choices comments
attach

no
A space-separated list of pathnames of files to attach to the message. Attached files will have their content-type set to application/octet-stream.
bcc

no
The email-address(es) the mail is being ‘blind’ copied to. This is a comma-separated list, which may contain address and phrase portions.
body

no $subject
The body of the email being sent.
cc

no
The email-address(es) the mail is being copied to. This is a comma-separated list, which may contain address and phrase portions.
charset

no us-ascii
The character set of email being sent
from

no root
The email-address the mail is sent from. May contain address and phrase.
headers

no
A vertical-bar-separated list of headers which should be added to the message. Each individual header is specified as header=value (see example below).
host

no localhost
The mail server
password

(added in 1.9)
no
If SMTP requires password
port

no 25
The mail server port. This must be a valid integer between 1 and 65534
secure

(added in 2.3)
no try
  • always
  • never
  • try
  • starttls
If always, the connection will only send email if the connection is Encrypted. If the server doesn’t accept the encrypted connection it will fail.
If try, the connection will attempt to setup a secure SSL/TLS session, before trying to send.
If never, the connection will not attempt to setup a secure SSL/TLS session, before sending
If starttls, the connection will try to upgrade to a secure SSL/TLS connection, before sending. If it is unable to do so it will fail.
subject

yes
The subject of the email being sent.
subtype

(added in 2.0)
no plain
The minor mime type, can be either text or html. The major type is always text.
timeout

(added in 2.3)
no 20
Sets the Timeout in seconds for connection attempts
to

no root
The email-address(es) the mail is being sent to. This is a comma-separated list, which may contain address and phrase portions.
username

(added in 1.9)
no
If SMTP requires username

Zhiming Zhang

Senior devops at Appannie
一个奔跑在运维路上的胖子
Zhiming Zhang

Latest posts by Zhiming Zhang (see all)

发表评论