我想使用yml
在ansible
文件中定义yml
个主机。
我的主机文件位于/etc/ansible/host
上,并且包含:
---
dev:
hosts:
host1: 10.13.212.32
但是我得到了错误:
[root@localhost host]# ansible dev -m ping
[WARNING]: Failed to parse /etc/ansible/hosts with yaml plugin:
Invalid data from file, expected dictionary and got: 10.13.212.32
[WARNING]: Failed to parse /etc/ansible/hosts with ini plugin:
/etc/ansible/hosts:48: Expected key=value host variable assignment,
got: 10.13.212.32
[WARNING]: Unable to parse /etc/ansible/hosts as an inventory source
[WARNING]: No inventory was parsed, only implicit localhost is available
[WARNING]: No hosts matched, nothing to do
这可能是什么原因?
答案 0 :(得分:-1)
阅读yaml配置插件documentation时,yaml有效扩展名是.json
,.yaml
和.yml
。
所以您需要
/etc/ansible/hosts
重命名为/etc/ansible/hosts.yaml
inventory = /etc/ansible/hosts.yaml
中设置/etc/ansible/ansible.cfg
ps:检查问题,因为您为库存文件写了host
和hosts