我正在看Ansible的教程,其中我必须部署一个playbook。实战手册代码如下:
- 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,还没有找到任何为什么会发生这个错误的提示!
发布于 2019-05-01 03:28:58
您的YAML相当于:
[
"name:\"Do a demo\" hosts:groupA\ntasks:- 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:- 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键。
https://stackoverflow.com/questions/55927155
复制相似问题