我正在尝试遵循本教程:
https://www.infinitypp.com/ansible/email-notifications-with-examples
我从中构建了以下名为test.yml的剧本,其中包含以下代码:
---
- name: sending an email
hosts: localhost
tasks:
- name: send email
local_action: mail
subject="ansible sent this"
to="my name <myemail.example.com>"
body="this is the body"
但是我收到此错误:
ERROR! 'mail' is not a valid attribute for a Play
The error appears to have been in '/path/test.yml': line 1, column 3, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
- name: Send email
^ here
我想知道我在做什么错
答案 0 :(得分:0)
您的Yaml格式错误,正确的剧本是:
---
- name: sending an email
hosts: localhost
tasks:
- name: send email
local_action:
module: mail
subject: "ansible sent this"
to: "my name <myemail.example.com>"
body: "this is the body"
使用local_action
时,应使用键module
指定模块。另外,对于键/值对,您应该使用:
,而不是=
。
答案 1 :(得分:0)
local_action
用于播放目标为localhost的主机,这是多余的。这不是错误,而只会增加混乱。如果您确实需要localhost委派(因为您打算在播放过程中以其他主机作为目标,同时仍从ansible控件发送邮件),请查看delegate_to
选项,该选项会产生更加易读的IMO任务(即{{1 }})这是一本更正后的剧本,可让您步入正轨。我保留了本地代理的示例。如果您不使用它,只需删除它。
delegate_to: localhost