本文介绍了Ansible Playbook:错误! “命令"不是Play的有效属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想写一个基本的剧本,并不断出现下面的错误.尝试了一吨的东西,但仍然无法解决问题.我知道这一定是语法问题,但不知道在哪里.

I'm just trying to write a basic playbook, and keep getting the error below.Tried a tonne of things but still can't get it right. I know it must be a syntax thing but no idea where.

这是我的代码:

---
# 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 ver: 2.4.2.0

它使我发疯.我看过Ansible文档中的一些示例,它看起来是一样的.不知道...

It's driving me insane. I've looked at some axamples from the Ansible docs, and it looks the same.No idea...

有人知道吗?

推荐答案

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

The problem being that without the indentation of the command line the command directive is part of the overall play and not the task block. i.e. the command should be part of the task block.

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

- hosts: nagios
  #remote_user: root

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

这篇关于Ansible Playbook:错误! “命令"不是Play的有效属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 21:53