hosts.ini
[local]
127.0.0.1 ansible_connection=local
hosts.yaml
local:
hosts:
127.0.0.1:
vars:
ansible_connection: local
然后我运行ansible local -m ping -i hosts.ini
我得到了预期的输出,然后我运行ansible local -m ping -i hosts.yaml
我得到了:
[WARNING]: * Failed to parse /home/elruso/projects/ansible/hosts.yaml with ini plugin: /home/elruso/projects/ansible/hosts.yaml:5: Expected key=value host variable assignment, got: local
[WARNING]: Unable to parse /home/elruso/projects/ansible/hosts.yaml as an inventory source
[WARNING]: No inventory was parsed, only implicit localhost is available
[WARNING]: Could not match supplied host pattern, ignoring: local
[WARNING]: No hosts matched, nothing to do
根据docs,我可以使用yaml文件作为库存而不会出现问题。如何指定使用yml插件?
$ansible --version
ansible 2.4.0.0
config file = /home/elruso/projects/ansible/ansible.cfg
configured module search path = ['/home/elruso/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/elruso/.virtualenvs/ansible/lib/python3.6/site-packages/ansible
executable location = /home/elruso/.virtualenvs/ansible/bin/ansible
python version = 3.6.2 (default, Jul 20 2017, 08:43:29) [GCC 5.4.1 20170519]
更新:issue已打开
答案 0 :(得分:1)
这个问题在Python 3中是可重现的,看起来像一个bug。
使用Python 2而不是Python 3,因为后者是not officially supported yet。
答案 1 :(得分:1)
在python 3上的ansible 2.4.0中存在一个错误(试图在字符串列表中找到.yml
个字节)。
此错误已在此提交https://github.com/ansible/ansible/commit/72bdf7aa7e1b867380201092dff65338d59cd8fa中修复,可能会以2.4.1发布。
答案 2 :(得分:0)
删除清单文件并在ansible控制器上重新创建它对我来说是固定的。