Ansible Playbook : ERROR! 'command' 不是 Play 的有效属性

标签 ansible

这个问题在这里已经有了答案:





ERROR! 'fail' is not a valid attribute for a Play

(1 个回答)



ERROR! 'file' is not a valid attribute for a Play [duplicate]

(1 个回答)



Ansible error stating: 'apt_repository' is not a valid attribute for a Play [duplicate]

(2 个回答)


3年前关闭。




我只是想写一个基本的剧本,并不断收到以下错误。
尝试了很多东西,但仍然无法解决问题。我知道这一定是语法问题,但不知道在哪里。

这是我的代码:

---
# This playbook runs a basic DF command.

- hosts: nagios
  #remote_user: root

  tasks:
  - name: find disk space available.
  command: df -hPT

这是我得到的错误:
> ERROR! 'command' is not a valid attribute for a Play
> 
> The error appears to have been in '/root/playbooks/df.yml': line 4,
> column 3, but may be elsewhere in the file depending on the exact
> syntax problem.
> 
> The offending line appears to be:
> 
> 
> - hosts: nagios   
    ^ here

Ansible 版本:2.4.2.0

它让我发疯。我查看了 Ansible 文档中的一些示例,它看起来是一样的。
不知道...

有人知道吗?

最佳答案

问题是没有命令行的缩进,命令指令是整个游戏的一部分,而不是任务块。即命令应该是任务块的一部分。

---
# This playbook runs a basic DF command.

- hosts: nagios
  #remote_user: root

  tasks:
  - name: find disk space available.
    command: df -hPT

关于Ansible Playbook : ERROR! 'command' 不是 Play 的有效属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49246837/

相关文章:

mysql - 为什么将 DB 密码放在 Trellis/Bedrock 的两个文件中?

ssh - ansible:使用 ssh key 身份验证但多次询问密码 - 为什么?

amazon-web-services - 用于下载文件的 S3 模块在 ansible 中不起作用

ansible - 目标主机文件中的 Ansible 嵌套子组

error-handling - Ansible:忽略 include_tasks 中的错误

loops - Ansible - with_sequence 循环的条件,其变量 end 可能小于 start

ansible - 保存临时 ansible shell 脚本而不是删除

ansible - 检测 Terraform 中的 Ansible 更改并执行它们

shell - Ansible Playbook 运行 Shell 命令

ansible 使用循环和多个变量