Now that we are on the topic of managing remote clients, it is important that we understand the syntax
that is used in host file.
Hosts.
File is where we keep all our remote clients information.
For Ansible, all remote clients are considered inventory in Ansible.
Ansible keeps inventory information in host file located SC Ansible hosts.
The host file is created during Ansible installation just like as if you are installing Linux operating
system.
The ETSI host file is created by default just like that.
When you are installing ANSIBLE software, it creates a host file inside ETSI Ansible directory.
All right, so now let's spend some time to understand how we could list our hosts or our remote clients
inside the host file.
All right.
So as an example, if you are if you catt the host file or by the host file, you'll see the clients
are listed either by the FCN, which is fully qualified domain name or with an IP address one client
listed in each line.
You cannot list two or three clients all in the same line.
Then another example of listing clients is by grouping them you see by app servers.
If you wanted to separate application servers, if you want to separate web servers or if you want to
separate the database servers, these are the headers that are used to group the clients.
Now another thing, keep in mind you do not need a header if you wanted to list all of these remote
clients in in one column because.
By default, the Ansible uses all as its to list all the clients inside the host so you don't have to
group them.
All right.
Another way that you could enlist your client, if they are in a sequential order, for example, if
you have an IP address that ends with one, one, one all the way through, 114, for example, you
have four of them.
Then you could list like in an IP range.
I'm sure if you're in a corporate environment, you probably have hundreds of server and they they are
in sequential order.
So you don't really have to go in and list them one by one because that could be tedious.
So you have a write shortcut right here by Ansible, and that is to define by the IP range.
You just have to put that range in the brackets and let Ansible pick your clients for you.
All right.
So now, as you know, we have the default location for these hosts and Etsy as host.
Now, if you decided to change the location of this inventory host file to a different location, that
is fine.
But you have to specify the location of the host file.
For example, you have to run the command ansible playbook to run a playbook.
But if you have the inventory host file in a different location, then you specify just like that but
minus I option and then the absolute or full path of the host file where is located and then followed
by the playbook that you wanted to run.
Another simple way to add your remote client information into host is by defining aliases.
So if you do not have a name or host name of your remote clients, just the IP, I know it is hard to
remember the High B's, so what you do is you define the aliases.
For example, in this case you have server one.
You define it by putting in space ansible underscore, ssh underscore host equal the IP address and
so on.
This will help you a lot when you are executing task to your remote client's inventory host file can
either be static or dynamic.
For that, you have to use additional plugins.
Now if you are wondering what is the difference, well, if you go back to your memory lane, you'll
remember when you create IP or when you assign IP to your hosts, you either assign a static or you
assign it dynamic when if it's static.
Of course it doesn't change.
You don't have to worry about it.
You put the static IP into the host file and you are done.
But what if it changes?
Then your host file can update that too as well.
Yes.
As well allows you to do that.
But as I said in the parentheses, you have to use an additional plugins for that.
All right.
Listing host file so you could list of what's inside of your host file by running the command ansible
dash, inventory, space, dash, dash or hyphen hyphen list.
This will list all the remote clients that you have inside of your host file.
All right, let's go to our Linux machine right here.
Let's log in.
I'm logged in as root and I am in Etsy and directory.
Let's do less minus L and you will see right here is the host file.
Now when you when I do CAD or more, let's do more on host file.
You will see that all the entire host file right now is commented out by the comment or hash tag right
here, which just tells you a provide some guidance as to how you could list your clients in the host
file right here.
This is example one is telling you specify before any group headers you can just simply put in the UN
name or IP address.
Second example, a collection of hosts belonging to the Web server group.
That's exactly what I mentioned in the previous slide.
You can separate them by grouping them.
But and you have to define the name of the group coming down just like that.
You have to define the range.
And example three.
Collection of database server.
You could group them as well.
Now, right now, everything in our hospital is commented out.
If you want to add an IP address, which we will be adding later on.
But for example, just for this lecture, if you wanted to edit it, you could just do them hose and
come down right here below the example one If you know the IP address, you could type it in here like
192 one 68.1.
For example, 25.
It is just a random IP I'm picking.
Let's save it.
And now we'll run the command.
Ansible.
Inventory Dash Dash listed.
This will list all the IP addresses that are active inside my host file.
And there it is.
It says there is one it found it is uncooked.
And that's the IP address.
Perfect.
Now we could go back to our host file and we could remove it because it was just a bogus IP, a fake
IP that I picked.
So I'm just going to save it without it.
And we will add the correct IP or the live IP of our remote clients in the next lectures.