![Ansible Playbook 语法检查问题](https://linux22.com/image/138010/Ansible%20Playbook%20%E8%AF%AD%E6%B3%95%E6%A3%80%E6%9F%A5%E9%97%AE%E9%A2%98.png)
我在 /etc/ansible/hosts 中有以下详细信息
[dev] 10.13.212.32
我可以 ping 该主机如下:
# ansible dev -m ping
输出:
[root@localhost ~]# ansible dev -m ping
10.13.212.32 | SUCCESS => {
"changed": false,
"ping": "pong"
当我检查 *.yml 文件的语法时。
# ansible-playbook --syntax-check --list-tasks -i hosts ./nginx.yml
或者
# ansible-playbook nginx.yml --check**
[WARNING]: Unable to parse /root/hosts as an inventory source
[WARNING]: No inventory was parsed, only implicit localhost is available
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'
ERROR! Syntax Error while loading YAML.
did not find expected '-' indicator
该错误似乎位于“/root/nginx.yml”:第 3 行第 1 列中,但可能位于文件中的其他位置,具体取决于确切的语法问题。
有问题的行似乎是:
- name: install and start nginx
hosts: localhost
^ here
帮我解决这个问题。
答案1
错误正如所言,没有/root/hosts
文件!
ansible-playbook --syntax-check --list-tasks -i hosts ./nginx.yml
使用-i
开关 ( --inventory-file
),您将指向文件/root/hosts
(因为您是root
从root
's运行$HOME
)而不是文件:
/etc/ansible/hosts
所以,再试一次:
ansible-playbook --syntax-check --list-tasks -i /etc/ansible/hosts ./nginx.yml
并且您的剧本由于语法和缩进不正确而失败。查看这个例子对于初学者。