INI vs YAML Inventory Files
Write hosts in both inventory formats.
INI vs YAML Inventory Files is a free Ansible Academy lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Ansible Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
What an Inventory Is
An inventory is just a file listing the hosts Ansible can manage. No hosts listed means nothing to automate.
Two Supported Formats
Ansible reads inventories in two flavors: the classic INI style and a structured YAML style. You pick one per file.
The Simplest INI Inventory
In INI format, one host per line is all you need to start. This file already manages two web servers.
web1.example.com
web2.example.comINI Groups in Brackets
An INI group header sits in square brackets, and every host below it belongs to that group until the next header.
[web]
web1.example.com
web2.example.comThe Same Thing in YAML
The YAML format nests everything under a top key called all, then groups, then hosts. More verbose, but clearer at scale.
all:
children:
web:
hosts:
web1.example.com:
web2.example.com:YAML Hosts End in a Colon
Each host in YAML is a mapping key, so it ends with a colon and an empty value. That blank value can later hold variables.
hosts:
db1.example.com:Point Ansible at the File
Tell commands which inventory to use with the -i flag. Without it, Ansible falls back to /etc/ansible/hosts.
ansible all -i inventory.ini --list-hostsVerify What Ansible Sees
Run --list-hosts to confirm your file parses and shows the hosts you expect. A great first sanity check.
ansible web -i inventory.yml --list-hostsThe all Group Is Free
Every host you list automatically joins the built-in all group. Target it to act on your entire fleet at once.
ansible all -i inventory.ini -m pingINI for Small, YAML for Big
Choose INI for quick, flat lists; reach for YAML once you need nested groups and lots of variables.
Mind the File Extension
Ansible guesses the parser from content, but a clear extension like .ini or .yml keeps teammates and editors happy.
Quick Check
You are writing hosts in YAML inventory format. How does each host appear?
Recap
An inventory lists your hosts in INI or YAML. INI is flat and quick; YAML nests under all for richer structure. 📋
Frequently asked questions
Is the “INI vs YAML Inventory Files” lesson free?
Yes — the full text of “INI vs YAML Inventory Files” is free to read here on the web, and the Ansible Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Ansible Academy course, upgrade to CoddyKit PRO.
What will I learn in “INI vs YAML Inventory Files”?
Write hosts in both inventory formats. You practise Ansible Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Ansible Academy?
No prior experience is required. Ansible Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “INI vs YAML Inventory Files” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Ansible Academy lesson?
Yes. Every Ansible Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- INI vs YAML Inventory Files
- Grouping Hosts: web, db & app
- Nested Groups & the children Keyword
- Host & Group Variables in the Inventory