Ansible Error Guide: 'Failed to parse ... with the inventory plugins' Inventory Error
Fix Ansible's 'Failed to parse /path with the inventory plugins: ini, yaml' error: diagnose bad inventory syntax, wrong file format, missing groups, and plugin selection.
- #ansible
- #troubleshooting
- #errors
- #inventory
Exact Error Message
[WARNING]: Unable to parse /home/deploy/project/inventory.ini as an inventory source
ERROR! Failed to parse /home/deploy/project/inventory.ini with the inventory plugins:
ini, yaml, toml, script, auto.
Failed to parse /home/deploy/project/inventory.ini with ini plugin: /home/deploy/project/inventory.ini:5:
Expected key=value, got: web-01 ansible_host 10.0.4.21
Failed to parse /home/deploy/project/inventory.ini with yaml plugin: Syntax Error while loading YAML.
Ansible tries each enabled inventory plugin in turn and reports why every one of them rejected the file. The useful detail is in the per-plugin lines (here, the ini plugin’s Expected key=value complaint at line 5).
What the Error Means
Ansible does not assume a fixed inventory format. It hands your inventory source to each enabled inventory plugin (ini, yaml, toml, script, auto, plus any configured dynamic plugins) and uses the first that parses successfully. When none can parse it, you get Failed to parse ... with the inventory plugins, followed by each plugin’s specific reason.
So this error means your inventory file is malformed for the format it appears to be, or it is in a format no enabled plugin understands.
Common Causes
- An INI-style inventory with a host line that is not valid
key=value(e.g.ansible_host 10.0.4.21missing the=). - A YAML inventory with indentation or syntax errors, or missing the required top-level
all:/plugin:structure. - A file with the wrong extension so the
autoplugin picks the wrong parser (a YAML file named.ini). - A dynamic inventory script that is not executable or prints invalid JSON.
- Mixing INI and YAML syntax in one file.
- A stray tab, BOM, or non-UTF-8 character in the inventory file.
How to Reproduce the Error
Write an INI inventory with a malformed host variable:
# inventory.ini
[web]
web-01 ansible_host 10.0.4.21
web-02 ansible_host=10.0.4.22
ansible-inventory -i inventory.ini --list
ERROR! Failed to parse /home/deploy/project/inventory.ini with the inventory plugins:
ini, yaml, ...
Failed to parse ... with ini plugin: inventory.ini:3: Expected key=value, got: web-01 ansible_host 10.0.4.21
Diagnostic Commands
Ask Ansible to parse and dump the inventory; this isolates inventory problems from playbook problems:
ansible-inventory -i inventory.ini --list
Render the group/host tree to confirm structure once it parses:
ansible-inventory -i inventory.ini --graph
Run with verbosity to see exactly which plugin Ansible tried and why each failed:
ansible-inventory -i inventory.ini --list -vvv
For a dynamic inventory script, run it directly to check it emits valid JSON and is executable:
./inventory.py --list | head
Step-by-Step Resolution
-
Read the per-plugin error lines. The line/column and reason from the plugin matching your intended format (e.g.
ini plugin: ...:5: Expected key=value) point straight at the broken line. -
Fix INI host variables to be
key=value:
[web]
web-01 ansible_host=10.0.4.21
web-02 ansible_host=10.0.4.22
- Fix YAML structure. A YAML inventory must be valid YAML with the expected layout:
all:
children:
web:
hosts:
web-01:
ansible_host: 10.0.4.21
-
Match the format to the extension. If the file is YAML, name it
.ymlsoautoselects the YAML plugin; do not put YAML in a.ini. -
Make dynamic inventory scripts executable and JSON-clean:
chmod +x inventory.py
./inventory.py --list | python3 -m json.tool >/dev/null
-
Remove hidden gremlins. Strip a UTF-8 BOM or stray tabs that break parsing.
-
Re-validate until it lists cleanly:
ansible-inventory -i inventory.ini --list
{
"web": { "hosts": ["web-01", "web-02"] }
}
Prevention and Best Practices
- Validate every inventory change with
ansible-inventory --list(or--graph) before running a play; it catches parse errors without touching hosts. - Keep one format per file and name files by their format (
.ini,.yml) so theautoplugin selects the right parser. - Lint YAML inventories with
yamllintto catch indentation and syntax issues early. - For dynamic inventory, add a CI check that runs the script and pipes it through a JSON validator.
- Avoid editors that insert tabs or a BOM into inventory files; configure them for spaces and UTF-8 without BOM.
- Enable only the inventory plugins you actually use in
ansible.cfgso the error output is short and relevant.
Related Errors
Unable to parse ... as an inventory source— the warning that precedes the fatal parse error.Specified inventory ... does not exist— the path is wrong, not the contents.[WARNING]: provided hosts list is empty— the file parsed but defined no hosts.Could not match supplied host pattern— inventory parsed fine but the pattern matched nothing.
Frequently Asked Questions
Why does Ansible list so many plugins in the error? It tries each enabled inventory plugin in turn. The error shows why every one rejected the file, so you can read the reason from whichever plugin matches your intended format.
My YAML inventory fails but looks fine. Check indentation (spaces, not tabs) and that it has the expected all:/children:/hosts: structure. Run it through yamllint to spot the exact line.
Can I mix INI and YAML in one file? No. Each file must be a single valid format. Mixing them guarantees every plugin fails to parse it.
My dynamic inventory script fails to parse. Ensure it is executable (chmod +x) and that ./script --list prints valid JSON with no extra output. For more inventory and connection patterns, see the Ansible guides.
Download the Free 500-Prompt DevOps AI Toolkit
500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.
- 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
- Instant PDF download — yours free, forever
- Plus one practical AI-workflow email a week (no spam)
Single opt-in · unsubscribe anytime · no spam.