Okay friends, so let's get hands on with Ansible.
So the first component that we are going to talk about is that Ansible
configuration file.
So if you happen to search for Ansible configuration file, you can click this
top link right here.
And notice it says here that certain settings in Ansible are adjusted with this
particular
file Ansible.cfg. Now one thing to note, Ansible is going to seek to find this
particular configuration
file in a variety of different places, each with a greater priority than the WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
file in a variety of different places, each with a greater priority than the
other.
Now it says here the pass where the configuration file is searched and listed
as in the reference
documentation. If we just click this link here, this here is effectively the
locations and priority
levels in which Ansible will look for this particular configuration file. So
the first thing is that
if you happen to set your own environment variable and point it to a particular
location,
this is the first and primary location where Ansible is going to seek to find
this particular
file. Now if you have not set this environment variable, the next place it's WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
file. Now if you have not set this environment variable, the next place it's
going to be checked
is for a file called Ansible.cfg in the current directory. So whatever you
happen to be running
Ansible from, it's going to say hey, is there a file in the same directory
right here called
Ansible.cfg and if it is, then it's going to look to use the configuration
specified within that
particular file. Now if you do not have the Ansible configuration file within
the current directory
where Ansible happens to be running, the next location is going to be in the WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
where Ansible happens to be running, the next location is going to be in the
user's home directory.
So we can see this via the tilde character, which we know is their home
directory. Now if
you've got a key now, you'll notice that we happen to have a dot before the
word Ansible.
Denoting that in this case here, this would actually be a hidden file. Now
suppose you have not created
any of these environment variables or the files in these particular directories
, the general system
way configuration file is going to be found in the exit directory and then into
the Ansible folder
and the file itself will simply be just called Ansible.cfg. That is the order WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
and the file itself will simply be just called Ansible.cfg. That is the order
of operation.
Now in my case here, the practice that I tend to follow is just simply putting
an Ansible.cfg
file within the directory in which I am working. You can specify anything you
so wish, but that
is the practice that I am going to be following. If you don't use that
particular practice,
just at least understand the order of operations and where Ansible is going to
look to find
that particular config. Now if we search Ansible inventory, let's collect this
link here.
If we scroll on down, we can see some examples of Ansible inventories. WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
If we scroll on down, we can see some examples of Ansible inventories.
Here we happen to have what is known as an Ansible inventory in the I and I
format.
Now the way we construct this is we specify our group names in square brackets.
So we have a
group here called web servers and inside of the web servers just below, we
specify the actual
nodes which belong to that particular group. So food.example.com and bar.
example.com,
they happen to be web server devices and below we have to have a grouping of
database servers,
DB servers and the nodes belonging to that particular group is one.example.com, WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
DB servers and the nodes belonging to that particular group is one.example.com,
two.example.com and three.example.com. Now in my opinion, this happens to be
the easier way to
happen to construct your Ansible inventory just as really simple, doesn't cause
any hassle.
But ultimately, I would say it's best suited for simple inventories.
If you just happen to have some groups, a few nodes belonging to those groups,
then it is a very good way to structure your Ansible inventory.
Below though, we can see the same type of information specified in the YAML WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
Below though, we can see the same type of information specified in the YAML
format.
Now the interesting thing here is with respect to YAML, we have a lot of
emphasis on indentation.
We'll talk about that a lot more in an upcoming skill. But basically, the
indentation is very,
very important if you happen to get the indentation wrong. The way the
information is ingested is
going to be completely different and in fact, it can just be invalid and will
not work. So in my
opinion, this is a little bit more complex because an armor rose to follow is
easier to get the syntax
wrong. However, if you happen to have groups within groups, i.e. nested groups WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
wrong. However, if you happen to have groups within groups, i.e. nested groups
and a much more
complex inventory, having that information represented in YAML format is
actually a lot
easier to look at visually because you can easily see via the indentation,
which group belongs to
which group and to quickly assess visually the order of the hierarchy. Now like
I say, for error
purposes, it's going to be really quite simple. So I'm just going to stick to
the i and i format.
But if you so wish, if you're more comfortable with YAML, then feel free to
construct your
inventory in that manner. So with that said, let's go and begin configuring our WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
inventory in that manner. So with that said, let's go and begin configuring our
Ansible
configuration file once again, I'm going to specify mine within my working
directory. So right now,
I'm inside of the Ansible home directory for the Ansible user. If we do a
listing, we can see we
have no files or directories within here. So what I'm going to do is I'm going
to create a particular
file just called Ansible dot CFG. If I create that do a listing, now that file
exists. But as we know,
there is no content within that particular file, let's add to it. So I will
just save them
Ansible CFG. If I hit i for insert, I can go into insert mode. And similar to WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
Ansible CFG. If I hit i for insert, I can go into insert mode. And similar to
the Ansible
inventory, this is also going to be written via the i and i format. So I'm
going to say within my
square brackets, I'm going to create my default group, which is going to
effectively denote my
default settings. Now the first directive I'm going to give is specifying where
about my
inventory can be located. Now by default, if you did not specify an inventory
location,
the default is going to be in the AC directory. And then within the Ansible
directory, there
should be a file called hosts. So if we don't specify here, Ansible will look WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
should be a file called hosts. So if we don't specify here, Ansible will look
to this particular
file. But in order to keep things simple, I'm going to specify the Ansible, she
looked within the
current directory for a particular file called inventory dot i and i. Now I'm
going to specify
the directive for the remote user, this is basically going to be the username,
the Ansible is going
to use in order to access the remote machines. Now remember, we created a
dedicated Ansible user
account on the devices that we're going to manage. So right here, we're going
to specify that Ansible
should actually use that particular account when logging in. Now I'm going to WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
should actually use that particular account when logging in. Now I'm going to
say host key checking,
we're going to specify that as false, we don't really care about key checking.
And then I'm going
to say deprecation warning pretty much very often, Ansible is going to give you
warnings about
modules and whatnot that happened to be outdated. We don't want to have to
worry about that. So I'll
just leave these warning messages set to false. So these are our default
configurations. What I
now want to do is to specify how Ansible can actually elevate privileges. You
know the way you do when
you happen to have a shell within a device, you can just say pseudo and then WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
you happen to have a shell within a device, you can just say pseudo and then
type in the super user
password. That is how we could perform an administrative system wide task. In
the case here, we want to
tell Ansible how to do that. So I'm going to say with thin mind square brackets
once again,
privilege escalation, basically how we can escalate our privileges. What I'm
going to say is become
equals true, which means we are going to seek to become the root user. I will
specify how we
actually elevate our privileges by specifying the become method. And I'll say
we do that via the
pseudo commands. And then I'll say the become user is simply the root user. And WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
pseudo commands. And then I'll say the become user is simply the root user. And
I will say become
ask pass. And I'll set that to the value false. We don't want to be asking for
passwords after all.
So what's that now done if I press escape and then colon wq to writing quit and
then hit enter,
we have now written this configuration file. Now as per the configuration file,
we specified that
there should be a file called inventory dot I and I within the same directory
right now that
doesn't exist. So let's just create it by saying touch inventory dot I and I,
if I don't LS,
now that file exists. And we want to actually specify the content of that file. WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
now that file exists. And we want to actually specify the content of that file.
So inside of
here, we are once again going to be using the INI format. So the grouping I'm
going to create
as within square brackets, I'm just going to create a group called all which
will specify
all of my devices. Now we can just specify the IP addresses of these particular
devices,
such as 192, 168, 160, and then specify 134, which would be the blue box and
then we can do the IP
address of 192, 168, 160 dot 135 for the yellow box. But quite honestly, this WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
address of 192, 168, 160 dot 135 for the yellow box. But quite honestly, this
is a little bit
clunky. We would rather have some type of name resolution. So before I actually
do this,
if I just press Q to quit, what I want to do is within my Etsy directory, so I
'll say pseudo
them, Etsy and going to the host file. This is where we can specify some static
DNS mappings.
So if I happen to say 192, 168, 160 dot 134, and if I just map that to the name
example dot blue
box dot com, and I'll give it a short name of blue box. And I'll also specify WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
box dot com, and I'll give it a short name of blue box. And I'll also specify
192, 168, 160,
dot 135. And I'll also say example dot yellow box dot com and we can reference
that as the
short name yellow box. If I just happened to press right and correct to safety
changes,
if I now just try to ping blue box, notice within here, we happen to be getting
the name
resolution we happen to be picking 192, 168, 160 dot 134. So because of this,
and by the way,
just similarly to prove this, if I say ping yellow box, we ping the other
address within the
answerable inventory, I'm just going to reference these host names. So once WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
answerable inventory, I'm just going to reference these host names. So once
again, go back into the
inventory, enter to the all group or specify we have a blue box and a yellow
box. And if I so
wished I could create more groups. Of course, we only have two devices, but
imagine you happen
to have 500 devices, maybe somewhere in the USA, I can say, okay, we have a USA
group,
and then list all devices that happen to be in the United States, like device
one, device two,
and then maybe we've got a group for the UK, maybe say, UK server, UK database,
whatever it may be, WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
whatever it may be,
you can create as many groups as you so wish, but like I said, we only have two
devices,
and we can reference those devices just by specifying the keyword all. That is
a group that houses
both of these devices. So really simple inventory we have right here, let's
press WQ to write
and quits. So with these basic components up and running, what I now want to do
is to ensure that
answerable can actually reach those devices within the all group, that is the
blue box and the yellow
box. And the answerable is actually able to successfully communicate and
authenticate with those
devices because remember we're not actually using any passwords, we're relying WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
devices because remember we're not actually using any passwords, we're relying
on those SSH keys.
So a simple test we can do is just simple say, answerable all to target the all
group,
and then I'll specify I want to use the module ping. If I hit answer, look at
this right here,
it says yellow box success, we're able to reach that device. And below here we
have the blue box
and also a success. With that now done, answerable is now operational, and it
is now fully capable
of automating our lab environments.