The Error
[WARNING]: Unable to parse /path/to/inventory as an inventory source
[WARNING]: No inventory was parsed, only implicit localhost is available
INI Format Issues
Correct INI Inventory
# inventory.ini
[webservers]
web1 ansible_host=192.168.1.10
web2 ansible_host=192.168.1.11
[dbservers]
db1 ansible_host=192.168.1.20
[webservers:vars]
ansible_user=deploy
http_port=80
[all:children]
webservers
dbservers
Common INI Mistakes
# WRONG — spaces around = in host vars
web1 ansible_host = 192.168.1.10
# RIGHT
web1 ansible_host=192.168.1.10
# WRONG — missing group header
web1
web2
# RIGHT
[webservers]
web1
web2
YAML Format Issues
Correct YAML Inventory
# inventory.yml
all:
children:
webservers:
hosts:
web1:
ansible_host: 192.168.1.10
web2:
ansible_host: 192.168.1.11
vars:
ansible_user: deploy
dbservers:
hosts:
db1:
ansible_host: 192.168.1.20
Common YAML Mistakes
# WRONG — hosts directly under group (missing 'hosts' key)
all:
children:
webservers:
web1: # ← Missing 'hosts:' level
ansible_host: 192.168.1.10
# WRONG — tabs instead of spaces
all:
children: # ← Tab character!
# WRONG — inconsistent indentation
all:
children:
webservers:
hosts:
web1: # ← 1 space instead of 2
Dynamic Inventory Issues
Script Must Be Executable
chmod +x inventory.py
./inventory.py --list # Test it
Must Return Valid JSON
# Test output
./inventory.py --list | python3 -m json.tool
Expected JSON Format
{
"webservers": {
"hosts": ["web1", "web2"],
"vars": {
"ansible_user": "deploy"
}
},
"_meta": {
"hostvars": {
"web1": {"ansible_host": "192.168.1.10"},
"web2": {"ansible_host": "192.168.1.11"}
}
}
}
Debugging Inventory
# Show parsed inventory
ansible-inventory -i inventory.yml --list
# Show as graph
ansible-inventory -i inventory.yml --graph
# Show specific host vars
ansible-inventory -i inventory.yml --host web1
# Verbose parsing
ansible-inventory -i inventory.yml --list -vvv
Multiple Inventory Sources
# Use a directory of inventory files
ansible-playbook -i inventory/ playbook.yml
# inventory/
# ├── 01-static.yml
# ├── 02-dynamic.py
# └── group_vars/
# └── all.yml
Conclusion
Inventory parsing errors usually come from format issues (wrong YAML indentation, missing hosts: key) or dynamic scripts that aren't executable or return invalid JSON. Use ansible-inventory --list to debug.