Telling Ansible About Your Servers
Before Ansible can manage any server, it needs to know those servers exist. The inventory is the source of truth for this information. It maps hostnames or IP addresses into named groups, which playbooks then reference as targets.
Think of the inventory as your address book. A playbook says "configure all the webservers" — the inventory is what defines which machines belong to the webservers group.
Static Inventory
The simplest inventory is a plain text file in INI format: hostnames or IPs listed under bracket-headed group names, with a [group:children] syntax that creates a group-of-groups — a staging group that automatically includes every host from both webservers and dbservers, for instance. Variables can attach directly to a host inline, or, for larger projects, live in separate files under group_vars/ and host_vars/ directories that Ansible reads automatically — one file per group or per specific host.
Dynamic Inventory Plugins
In cloud environments, servers are created and destroyed constantly by autoscaling groups. A static text file becomes obsolete within minutes. Dynamic inventory plugins solve this by querying a cloud provider's API at runtime to build the inventory on the fly. For AWS, the plugin is configured with a small YAML file naming the regions and tag filters to query and how to group the results — a server tagged with a given role automatically appears in a correspondingly-named group, with no one maintaining a host list by hand. The pattern is the same across providers — GCP, Azure, VMware, Kubernetes, and many other platforms all expose an equivalent plugin: a small config file that tells it how to query the API and how to group the results.