ansible 2.7.10 - "ERROR! playbook entries must be either a valid play or an include statement|"中此错误的



我正在观看一个可以部署剧本的Ansible教程。播放书代码如下:

- name:"Do a demo"
  hosts:groupA
  tasks:!!seq
    - name:demo task 1
      debug:!!seq
        msg:"this is task 1"
    - name:demo task 2
      debug:!!seq
        msg:"this is task 2"
- name:"Do another demo"
  hosts:groupB
  tasks:!!seq
    - name:demo task 3
      debug:!!seq
      msg:"this is task 3"
    - name:demo task 4
      debug:!!seq
        msg:"this is task 4"

当我尝试使用ansible-playbook -i hosts demoplays.yaml命令部署上述播放书时,错误的错误是: -

ERROR! playbook entries must be either a valid play or an include statement
The error appears to have been in '/home/user/demoplays.yaml': line 1, column 3, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:

- name:"Do a demo"
  ^ here

首先,我将其视为YAML语法错误,但是YAML Linter验证了它是正确的。我在基础OS Loki系统上使用Ansible 2.7.10。我刚刚开始学习Ansible和YAML,但没有找到任何错误发生的暗示!

您的yaml等于:

[
  "name:"Do a demo" hosts:groupAntasks:!!seq - name:demo task 1 debug:!!seq msg:"this is task 1"n- name:demo task 2 debug:!!seq msg:"this is task 2"", 
  "name:"Do another demo" hosts:groupBntasks:!!seq - name:demo task 3 debug:!!seq msg:"this is task 3"n- name:demo task 4 debug:!!seq msg:"this is task 4""
]

这可能不是您想要的。尝试更改它,以使您的yaml中的根级序列的项目成为映射:

- name: "Do a demo"
  hosts: groupA
  tasks: !!seq
    - name: demo task 1
      debug: !!seq
        msg: "this is task 1"
    - name: demo task 2
      debug: !!seq
        msg: "this is task 2"
- name: "Do another demo"
  hosts: groupB
  tasks: !!seq
    - name: demo task 3
      debug: !!seq
        msg: "this is task 3"
    - name: demo task 4
      debug: !!seq
        msg: "this is task 4"

请注意,我不仅在结肠后添加了一个空间,我还缩进了msg: "this is task 3"以确认其他msg键。

相关内容

最新更新