YAML库存解析错误

问题描述:

hosts.iniYAML库存解析错误

[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

127.0.0.1:'末尾是否有':'? –

+0

@JimWright yes http://docs.ansible.com/ansible/latest/intro_inventory.html –

的问题是在Python 3重现性好,看起来像一个错误。

使用Python 2而不是Python 3,因为后者是not officially supported yet

+0

看起来很伤心,但我看到“Ansible只支持Python版本3.5及以上版本。”跟随你的链接,我有Python 3.6.2 –

+2

但它不像你可以采取任何字符串的背景和声称它是真实的。文章首先明确声明了“Python 3支持的技术预览*,仅包含预览版本,包括3.5” – techraf

在python 3的2.4.0中存在一个错误(试图在字符串列表中找到.yml字节)。

这个bug已经修复在这个提交https://github.com/ansible/ansible/commit/72bdf7aa7e1b867380201092dff65338d59cd8fa,它可能会被释放为2.4.1。

+0

但您知道您正在回复提交GitHub上的同一个人? – techraf

+1

是的,但不要别担心,我还在这个问题上记录了这个问题:https://github.com/ansible/ansible/issues/30977#issuecomment-333460412,这样任何在这里或在github上登陆的人都可以理解正在发生的事情以及预计何时会发布。 –