did not find expected <document start>
Asked Answered
F

6

10

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
Felten answered 10/10, 2019 at 6:29 Comment(5)
YAML document optionally starts with --- . Run ansible-config dump | grep INVENTORY and try to find out why yaml plugin is used.Bonita
Run ansible-inventory --list -vvv and see logs from the parsing methods. "yaml plugin" works for me with ansible 2.8 both with and without document start --- . No syntax errors or warnings.Bonita
The inventory example from the question Ansible 2.8 "parsed ... inventory source with ini plugin' without complaints.Bonita
I added the requested information.Felten
I encountered this problem because I added my command flags in the wrong order: ansible -ivvv somehosts. ansible -vvvvi somehosts workedStellastellar
I
3

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.

Imagery answered 19/4, 2020 at 4:51 Comment(0)
U
1

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.

Unused answered 15/7, 2020 at 1:58 Comment(0)
O
0

This occurs when there is some syntax issue in the inventory file.

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

Mine was because of the space _ in between ansible_user= and {{dest_user}}

Offertory answered 24/7, 2020 at 10:32 Comment(0)
T
0

It seems to be a generic "something went wrong in parsing your inventory" kind of error.

For me this happened when the host group referenced by another group that was defined in a different ini file in the inventory directory, i.e.

myinventory/a:

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

myinventory/b:

[child-host-group]
some.hosts

ansible-playbook -i myinventory ...

The workaround was to add an empty group entry for the child group to the referencing file:

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

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

Here is a reference to the official docs

Tenedos answered 29/12, 2020 at 10:56 Comment(0)
K
0

i put

[servers]

as first line solve same problem

Kyne answered 22/7 at 7:59 Comment(0)
A
-4

If this is your actual hosts content, it should work, but maybe you use another hosts file. You can specify your custom hosts or inventory file with this command:

ansible-playbook -i /path/to/your/custom/file

Please put your actual hosts file (stripped of sensitive data) inside the question for review.

Ametropia answered 12/2, 2020 at 15:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.