Overview

In Ansible, sometimes we have to apply script to A LOT of servers. Of course it isn't good idea to do it individually. We can set up inventory with groups of servers. An the Ansible engine will apply the changes to that group. Of course we need to set up inventory fail, which is simply a text file in either:

YML Format

INI Format

Here, we will use the INI format as I find it better to organize, please use whichever you prefer. You can think of the inventory as teh hosts file in Linux. It is also convenient as it is called the same, just it resides in: /etc/ansible/hosts

Setup

To setup inventory file, we need to go to the base location for ansible: “/etc/ansible” and create a file called “hosts” Then we can add something like this:

Now, that is very small inventory, but it illustrates a lot of features of the intenroy. So let's discuss them:

Groups

You can see, we have two groups:

kerberos_master

kerberos_nodes

And both of them are nested into 3rd group called: kerberos_servers

Variables

Furthermore, we can set variables which will affect a certain groups or a particular server. For example we have set that for all servers, the engine will use:

User: Vagrant

Password: Vagrant

Connection: SSH (as they are Linux servers), but can be also winrm (if they were Windows)

Alternatively, we can set a vaiable for particular host or group, as seen here:

In that case, the engine will ignore the default port (22) and it will use port 5678 to connect.

Check

So we can create that file:

We can also execute a module against a certain group or server: