Ansible Configuration Inventory

Ansible Configuration Inventory

Uncategorized

[stm_post_details]

What is an Ansible Inventory?

The Ansible Inventory is a highly customizable component of Ansible. It is a configured location where you can place credentials of the remote hosts, such as IP Address and Username. With Ansible, you can effortlessly classify or group nodes depending on the type of application being used. Ansible Inventory is highly customizable, and can efficiently work with dynamic sources such as the cloud.

Ansible allows you to work with multiple inventory files at the same time. This way, you can accomplish a number of tasks in a limited project timeline.

How to create an Ansible Inventory?

Creating an Ansible inventory is easy. It is just a plain text file written in YAML format. Optionally, you can also write them in JSON format. Any text editor or IDE can be used to write these files. Here we are using Microsoft Visual Studio Code.

You can execute node classification based on Operating System type, to find out the operating systems of the two remote hosts.

Let’s create a new inventory file here. On the left-hand side pane, at the top, click the New File icon next to WORKSPACE. Let’s name this file as inventory. The moment you start typing on this page, it shows inventory as an open editor on the left-hand pane. This makes it easy to keep track of the editors that are in progress.

In the inventory file, input the IP addresses and usernames for the target remote servers you intend to configure using Ansible. This way, it informs Ansible that these are the servers to be managed.

Let’s say you have two servers to manage – one is an Ubuntu machine, and another one is a Fedora machine. On the first line, you can enter the IP address of the Ubuntu VM, followed by the variable for the username along with the input value: 192.168.180.131 ansible_ssh_user=tetra-noodle. On the second line, let’s enter the same variable for the Fedora VM, that is IP address, followed by variable for username and then the input value: 192.168.180.136ansible_ssh_user=tetra-noodle. You can easily check for reachability of the remote servers through the inventory file, by using the Ping Test.

Executing this test is as simple as running the command:

ansible all -m ping -i inventory

Here ansible is the main command. “all” stands for all target hosts.

Hyphen M stands for the name of the Ansible module being used – which in this case is ping.

Hyphen I stands for the inventory file.

This screenshot shows a successful ping test conducted via Ansible.

Ansible

You can also classify the target nodes into groups of servers. To understand the concept of node classification better, you can use a rule to classify the entries, say, using server type. For instance, let’s say that you want to host a webserver on the Ubuntu VM, and a MySQL database on the Fedora VM.

To start with, you need to configure the web server on the Ubuntu VM, replace ubuntu with webserver in the square brackets. Let’s configure the database server on the Fedora VM by replacing fedora with dbserver.

Fedora VM by replacing fedora with dbserver

Now, you can run the ping test for the webserver and database server. You can use the integrated terminal in Visual Studio Code to run these commands.

The ping test commands you can use for the two servers are:

For the webserver

ansible webserver –m –i inventory

For the database server

ansible dbserver –m –i inventory

Using this feature of Ansible, you have the flexibility in specifying the nodes on which you want to run the Ansible Playbooks.

You can efficiently run your IT configurations using the inventory file. You can use Ansible to run multiple environments seamlessly. Ansible works smoothly with multiple cloud platforms and data center infrastructures. This helps you achieve your business goals for IT innovation and progress. Ansible’s deployment solutions are exactly what your IT automation processes need!

[stm_post_bottom][stm_post_about_author][stm_post_comments]
[stm_sidebar sidebar=”1118″]

Leave a Reply

Your email address will not be published. Required fields are marked *