找不到预期的<document start>

时间:2019-10-10 06:29:00

标签: ansible ansible-inventory

Ansible正在读取/etc/ansible/hosts文件,并给出了我不理解的错误。

ARNING]:  * Failed to parse /etc/ansible/hosts with yaml plugin: Syntax
Error while loading YAML.   did not find expected <document start>  The error
appears to be in '/etc/ansible/hosts': line 2, column 1, but may be elsewhere
in the file depending on the exact syntax problem.
  1. 为什么Ansible尝试使用yaml插件解析此INI样式的文件?

  2. <document start>是什么?我在任何文档中都找不到

文件看起来像这样(不实际)

[first_group]
host-1 ansible_host=1.1.1.1
host-2 ansible_host=2.2.2.2

谢谢。

编辑:

更多信息:

ansible@ansible:~$ ansible-config dump | grep INVENTORY
DEFAULT_INVENTORY_PLUGIN_PATH(default) = [u'/home/ansible/.ansible/plugins/inventory', u'/usr/share/ansible/plugins/inventory']
INVENTORY_ANY_UNPARSED_IS_FAILED(default) = False
INVENTORY_CACHE_ENABLED(default) = False
INVENTORY_CACHE_PLUGIN(default) = None
INVENTORY_CACHE_PLUGIN_CONNECTION(default) = None
INVENTORY_CACHE_PLUGIN_PREFIX(default) = ansible_facts
INVENTORY_CACHE_TIMEOUT(default) = 3600
INVENTORY_ENABLED(default) = ['host_list', 'script', 'auto', 'yaml', 'ini', 'toml']
INVENTORY_EXPORT(default) = False
INVENTORY_IGNORE_EXTS(default) = {{(BLACKLIST_EXTS + ( '.orig', '.ini', '.cfg', '.retry'))}}
INVENTORY_IGNORE_PATTERNS(default) = []
INVENTORY_UNPARSED_IS_FAILED(default) = False

5 个答案:

答案 0 :(得分:1)

当您的子标题与父母未排成一行时,可能会发生这种情况。例如:

[webservers]
1.2.3.4
1.2.3.5

[webserver:vars]
ansible_python_interpreter=/usr/bin/python3

仔细观察,webservers!= webserver。添加s,就可以了。

我在Google上也遇到了同样的错误,这使我到了这里。

答案 1 :(得分:0)

当我重新安装ansible并将/etc/ansbile/ansible.cfg默认返回初始状态时,为我纠正了该错误。清单文件实际上很好。该问题似乎与我修改过的广告资源插件有关。

答案 2 :(得分:0)

库存文件中存在语法问题时,这种说法很准确。

[local]
localhost
[dest]
{{ dest_server }} ansible_user= {{dest_user}} ansible_password= {{dest_passwd }}

我的原因是ansible_user =和{{dest_user}}之间的空格(_)

答案 3 :(得分:0)

这似乎是一个通用的“解析您的库存时出现问题”类型的错误。

对我来说,这发生在另一个组引用的主机组时,该组在清单目录中的不同文件中定义,即

myinventory/a.yml

[parent-host-group:children]
child-host-group

myinventory/b.yml

[child-host-group]
some.hosts

ansible-playbook -i myinventory ...

解决方法是将子组的空组条目添加到引用文件中:

[child-host-group]
# See b.yml - just defined here to make parent-host-group work

[parent-host-group:children]
child-host-group

答案 4 :(得分:-2)

如果这是您实际的“主机”内容,则必须起作用,但是也许您使用其他主机文件。您可以指定您的自定义主机或清单文件购买此命令:

df_desired
ID      assoc_rate   assoc_grade   PIR   new_rate 
124575  10.80        7             min     13.00      
123413  11.42        7             X2      13.98     
111539  11.65        8             X1      13.48     
112284  12.04        8             X2      13.98     
125245  12.10        9             min     13.00     
132588  12.44        9             X1      13.48 
....

Here are the dataframes:
df1 <- data.frame(grade = c(7L, 8L, 9L, 7L, 8L, 9L, 7L, 8L, 9L,7L, 8L, 9L, 7L, 8L, 9L), PIR = c("min", "min", "min", "X1", "X1","X1", "X2", "X2", "X2", "X3", "X3", "X3", "X4", "X4", "X4"),rate = c(10.8, 11.26, 12.1, 11.17, 11.65, 12.56, 11.55, 12.06, 13.03, 11.95, 12.49, 13.53, 12.35, 12.93, 14.04))
df2 <- data.frame(grade = c(7L, 8L, 9L, 7L, 8L, 9L, 7L, 8L, 9L,7L, 8L, 9L, 7L, 8L, 9L), PIR = c("min", "min", "min", "X1", "X1","X1", "X2", "X2", "X2", "X3", "X3", "X3", "X4", "X4", "X4"),new_rate = c(13, 13, 13, 13.48, 13.48, 13.48, 13.98, 13.98,13.98, 14.5, 14.5, 14.5, 15.04, 15.04, 15.04))
df3 <- data.frame(ID = c(124575, 123413, 111539, 112284, 125245, 132588), assoc_rate = c(10.80,11.42,11.65,12.04,12.10,12.44), assoc_grade = c(7,7,8,8,9,9))

请放置实际的主机文件,不要包含敏感数据。