Foundations / Lesson 2 of 3
Inventory
Tell Ansible which machines exist, how they are grouped and what settings they need.
6 min Beginner 7 steps
IN THIS LESSON
Step 1 of 7
STEP 1 / 7
An inventory is a list of hosts
The simplest inventory is a text file with one host per line. Ansible reads it to learn which machines it may manage.
web1.example.com
web2.example.com
db1.example.com← → step · R replay · Space play/pause
YOU'LL LEARN
- How hosts and groups are written in an inventory
- How group variables avoid repetition
- How to target a group from the command line
- What a dynamic inventory is
- An inventory is a list of hosts. The simplest inventory is a text file with one host per line. Ansible reads it to learn which machines it may manage.
- Group hosts by role. Put hosts under group names in square brackets. Groups let you act on every machine of one kind at once, such as all web servers.
- More groups, same file. A host can belong to several groups, and groups can contain other groups. That lets you slice your estate by role, environment or location without duplicating hosts.
- Set values per group. Variables that apply to a whole group live in a group_vars folder, in a file named after the group. Every host in that group picks them up automatically.
- Target a group. On the command line, name a group to run against only those machines. The same works in a playbook through its hosts line.
- Dynamic inventory. In the cloud, machines come and go, so a hand-written file goes stale. Inventory plugins ask the cloud provider's API for the current list of machines, and can group them by tags.
- Recap. The inventory is Ansible's map of your machines.