Managing your Ansible Inventory
In this lesson, you will learn about managing your Ansible Inventory. By the end of this lesson, you should understand what an Ansible inventory is, how to define it, and the significance of organizing hosts and groups for efficient automation tasks.
This lesson will be completed on the ansible-controller VM, so if you're not already logged into that VM, go ahead and do so now.
What is an Ansible Inventory?
An Ansible Inventory is a file (usually named inventory) that lists all the nodes or hosts that are reachable by Ansible. This file is used by Ansible to communicate with the machines you want to automate tasks on. A typical Ansible setup involves multiple machines, and the inventory file is where you define these machines and organize them.
Defining a Custom Inventory File
To start, let's create custom project directory named code, then we'll CD into the new directory:
Next we need to create a basic inventory file. This file can be in INI or YAML format. Here, we will use the INI format for simplicity. Create a file named inventory in your working directory with the touch command:
__
You will need to CD into the ~/code directory from now on when you run Ansible because this is where we are saving our config
Next, add either the following INI formatted or YAML formatted configuration to define our inventory:
In this example, there are two groups: webservers and controllers. Each group contains the respective hosts. The group names can be anything that makes sense for your setup. Here is the equivalent inventory in YAML format:
webservers:…
No comments yet. Add the first comment to start the discussion.