Inventory
Ansible inventory is a crucial component in Ansible, helping you manage the hosts you want to automate tasks on. It defines a collection of hosts, which can be grouped, organized, and assigned variables. There are two main types of Ansible inventory:
Static Host Inventory: Manually created text files with a list of hosts, groups, and variables. Suitable for a set of servers that don’t change frequently.
Dynamic Host Inventory: Generated dynamically using Ansible plugins based on external information sources. Ideal for large, dynamic environments with frequently changing hosts.
Static Inventory
In Ansible, a static inventory is a text file that lists the servers (managed hosts) you want to work with. It can be created in various formats, but we’ll focus on the common INI-style format for this guide.
Basic Inventory Example
Organizing Host into Groups
To better manage your inventory, especially when you have different categories of servers, you can group hosts together.
This approach is valuable for our web hosting company example. In the INI-style format, square brackets ([]
) are used to define host groups.
Grouped Inventory Sample
Host Groups: Categorizing Your Servers
In your Ansible inventory, you define host groups by enclosing them in square brackets ([]
). These host groups serve as a way to categorize your servers based on their specific roles or attributes.
For example, in the context of a web hosting company:
[web_servers]
may contain servers responsible for hosting websites.[db_servers]
could include servers designated for database management.[backup_servers]
might have servers dedicated to backup and data recovery.
Benefits of Host Groups
Efficient Task Execution
Simplified Management
Customized Configurations
Special Host Groups
In addition to user-defined host groups, Ansible automatically creates two special host groups:
all
: This special group contains every host explicitly listed in the inventory. It includes all the hosts you define in your inventory file.ungrouped
: Theungrouped
group contains hosts that are not assigned to any other group. These are individual hosts that are not categorized into user-defined groups.
Modules
ansible modules are the reusable scripts that helps in carrying out specific tasks on remote systems such as managing the packages, files, services or executing commands. It helps in automating the infrastructure management efficiently, consistently at scale.
yum
apt
git
copy
Last updated