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/hostsdoes 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
EOF2. Use a custom inventory instead
ansible-inventory -i ./my-hosts.ini --listCreate my-hosts.ini:
[all]
server1 ansible_host=10.0.0.1
server2 ansible_host=10.0.0.23. Verify the file is readable
ls -la /etc/ansible/hosts
sudo chmod 644 /etc/ansible/hosts4. Test with a basic ping
ansible all -i /etc/ansible/hosts -m ping -kFAQ
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro