【问题标题】:Ansible Playbook: ERROR! 'command' is not a valid attribute for a Play [duplicate]Ansible 剧本:错误! “命令”不是播放的有效属性[重复]
【发布时间】:2018-03-13 01:17:37
【问题描述】:

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

这是我的代码:

---
# 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 文档中的一些示例,看起来都一样。 不知道...

有人知道吗?

【问题讨论】:

  • 您是传入带有 -i 标志的清单文件还是 /etc/ansible/hosts 中的主机块 ([nagios])?
  • 我问的原因是因为违规行似乎是 4,您的主机声明。查看 ansible run linux.die.net/man/1/ansible-playbook 的手册页,-i 选项是主机文件的路径,默认为 /etc/ansible/hosts。无论您使用什么库存文件,都需要在其中包含 [nagios] 块。
  • 嗨,Jesse,更正 ([nagios]) 位于 /etc/ansible/hosts 的 hosts 文件中。还尝试了带有路径的 -i 选项,但仍然没有成功。在提示符下运行一个衬里,例如 ansible -m command -a 'df -hPT' nagios 工作正常,所以我可以排除我在 hosts 文件中的条目是问题所在。谢谢你的想法顺便说一句......
  • 哦,对不起,命令前面需要一个制表符吗?在这里查看命令文档:docs.ansible.com/ansible/latest/command_module.html
  • @Jesse 在“命令”模块之前放置了一个选项卡,现在错误是:违规行似乎是......并且在命令语句末尾的冒号下方有一个箭头。

标签: ansible


【解决方案1】:

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

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

- hosts: nagios
  #remote_user: root

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-12-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-02
    • 2016-01-20
    • 1970-01-01
    相关资源
    最近更新 更多