The Ansible inventory is all about telling Ansible about
the servers that you want to manage.
Ansible can manage only the servers it explicitly knows about.
Ansible comes with one default server. This is localhost,
which is the control host.
So you provide Ansible with information about servers by
specifying them in what's known as an inventory.
We usually create a directory called inventory to hold this type of information.
So a very simple inventory file might just contain a list of hostnames.
An Ansible inventory is a system that a playbook runs against.
It is a list of systems in your infrastructure that
the automation is executed against.
So these are a collection of hosts that commonly have hosts and
book and comprise of network devices and storage arrays and
other physical or virtual appliances.
It also has useful information that can be used alongside
our targets using playbook execution.
So the inventory can be really simple,
just like a text file, or it can be more dynamic where the inventory is an
executable where the data is sourced dynamically. This way, we can store data
externally that can be used during runtime. So, for example, we could have a
dynamic inventory via AWS, or we could create our own dynamic inventory. To
better organize your inventory,
we can have several groups for our different hosts,
such as a web group or a database group.
The web group in the inventory can have an inventory with multiple
playbooks hitting this group. So you can have different playbooks
running on only different parts of the inventory.
So basically, in Ansible, nothing happens without an inventory.
Even ad hoc actions that just perform simple tasks cannot be
performed unless you have an inventory.
So the inventory can be quite small, or it may just consist of a
localhost. Still, an inventory needs to be specified.
So in summary,
the inventory is the most basic building block of the
Ansible architecture. And when you're executing Ansible or
using the ansible‑playbook command, the inventory must be referenced.
There are ways to make Ansible more automated where we don't need to
reference the inventory, and we'll be looking at this very soon.
So just to summarize up,
the inventory can be static or dynamic or even a combination of
both. Ansible is not limited to a single inventory.
So the standard practice is to split the inventories across logical
boundaries. You could do this, for example, staging or production,
and then you can have an engineer to run a set of plays against their staging
environment for validation and then follow the exact plays or different plays
to run against the production inventory set.