Skip to content
FATAL: Unable to parse /etc/ansible/hosts as an inventory source

FATAL: Unable to parse /etc/ansible/hosts as an inventory source

DodaTech 2 min read

The error “FATAL: Unable to parse /etc/ansible/hosts as an inventory source” means Ansible could not read or understand your inventory file. It defaults to /etc/ansible/hosts when no inventory is explicitly provided.

What It Means

Ansible requires an inventory file that lists the hosts and groups it manages. When the default file at /etc/ansible/hosts is missing, malformed, or uses an unreadable format, Ansible fails before running any playbook or module.

Why It Happens

  • The file /etc/ansible/hosts does not exist.
  • The file exists but is empty or contains invalid syntax.
  • The file uses an INI format with incorrect section headers or spacing.
  • The inventory file has incorrect permissions (not readable by your user).
  • You specified a custom inventory path that does not exist or is malformed.

How to Fix It

1. Create the default inventory file

sudo mkdir -p /etc/ansible
sudo tee /etc/ansible/hosts <<EOF
[webservers]
web1 ansible_host=192.168.1.10
web2 ansible_host=192.168.1.11

[dbservers]
db1 ansible_host=192.168.1.20
EOF

2. Use a custom inventory instead

ansible-inventory -i ./my-hosts.ini --list

Create my-hosts.ini:

[all]
server1 ansible_host=10.0.0.1
server2 ansible_host=10.0.0.2

3. Verify the file is readable

ls -la /etc/ansible/hosts
sudo chmod 644 /etc/ansible/hosts

4. Test with a basic ping

ansible all -i /etc/ansible/hosts -m ping -k

FAQ

What formats does Ansible support for inventory?
Ansible supports INI, YAML, and dynamic inventory scripts. INI uses [group] headers with host var=val entries. YAML uses lists and dictionaries under all: and group keys.
Can I use a dynamic inventory script instead?
Yes. Any executable script that outputs valid JSON on stdout can serve as an inventory. Pass it with -i ./ec2.py or set inventory = ./ec2.py in ansible.cfg.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro