Ansible course
CHAPTER 03
Inventory
How Ansible knows which machines to manage
8 min read3 sections
In this chapter
What is an inventory?Inventory fileDynamic inventory
01What is an inventory?
An inventory is a file that lists the machines Ansible manages. It can be a simple INI file or a dynamic script that queries a cloud provider.
Why this exists
Without an inventory, Ansible doesn't know what to manage. The inventory is the address book.
02Inventory file
Groups organize machines by role. You can target a group (webservers) or a single machine (web1). Variables can be set per host or per group.
[webservers] web1 ansible_host=192.168.1.10 web2 ansible_host=192.168.1.11 [dbservers] db1 ansible_host=192.168.1.20 [all vars] ansible_user=deploy ansible_ssh_private_key_file=~/.ssh/id_ed25519
03Dynamic inventory
Instead of a static file, you can use a script that queries AWS, Azure, or GCP to get the current list of machines. Essential for cloud environments where IPs change.
Mental model
Static inventory is like a printed phone book. Dynamic inventory is like a live directory that updates automatically.
Check your understanding
0 / 1 correct
What is an inventory in Ansible?