我正在观看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,还没有发现任何提示发生该错误的提示!
答案 0 :(得分:3)
您的YAML等效于:
[
"name:\"Do a demo\" hosts:groupA\ntasks:!!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:groupB\ntasks:!!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
键。