首页 > 解决方案 > 从 ansible 发送电子邮件,邮件不是 Play 的有效属性

问题描述

我正在尝试遵循本教程:

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

我想知道我做错了什么

标签: ansible

解决方案


您的 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,应使用 key 指定模块module。此外,您应该使用:键/值对,而不是=.


推荐阅读