Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

did not find expected <document start>

Ansible is reading /etc/ansible/hosts file and giving errors that I don't understand.

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. Why is ansible trying to parse this INI-style file with yaml plugin?

  2. What is <document start>? I can't find this in any documentation

The file looks something like this (not actual)

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

EDIT:

More information:

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
like image 615
stone.212 Avatar asked Oct 10 '19 06:10

stone.212


2 Answers

This may occur when your sub-headers don't line up with their parents. For example:

[webservers]
1.2.3.4
1.2.3.5

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

Look closely, webservers != webserver. Add the s and you should be good to go.

I Google'd the same error, which brought me here.

like image 103
ExactaBox Avatar answered Nov 09 '22 18:11

ExactaBox


The error for me was corrected when I reinstalled ansible and defaulted the /etc/ansbile/ansible.cfg back to the original state. The inventory file was actually fine as it was. The issue appeared to be related to the inventory plugins that I had modified.

like image 33
Glenn B. Avatar answered Nov 09 '22 20:11

Glenn B.