无法在/ etc / ansible / hosts中使用yml格式

时间:2018-08-07 11:25:55

标签: centos ansible debian

我想使用ymlansible文件中定义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

这可能是什么原因?

1 个答案:

答案 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:检查问题,因为您为库存文件写了hosthosts