So friends, now we have all of the building blocks in place.
Let's now begin configuring our very first Ansible Playbook.
So if I do a listing, what we can see here is I have my configuration file,
I have my inventory file, as well as two folders containing my variables,
one for group, the other for host membership.
In this particular directory, what I will do is I'll create a Playbook,
which is called as Playbook1.yml, and all I will do is open this one up.
Now, fair warning, if this is the first time you're seeing an Ansible Playbook,
then there is a chance that it's going to look a little bit confusing. WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
then there is a chance that it's going to look a little bit confusing.
There's no escaping that. That is simply because it's just new to you,
and as you get more familiar with Ansible Playbooks, you begin to see it's
really the same kind of thing
over and over and over again. The structure is really quite similar.
So basically trying out to get too intimidated.
At the very top, what I'm going to do here is to create a name of the Playbook,
and you can call this "N" to use a wish. So I'm going to use the name key,
and now I specify my name.
Let's just call this "NTP Playbook" because essentially that's what I'm going
to do.
Now, super, super important. We're going to use this host keyword. WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
Now, super, super important. We're going to use this host keyword.
This is an Ansible convention, and this is how we specify to Ansible which
host to be wish to target. So in my case here, I wanted to deploy NTP to all
four of my devices.
So if we actually think about it, if I look at my inventory,
if I specify the Cisco group, well, that is actually going to target all four
devices right there.
That encompasses all those devices. So this is what I will do. So I'll just say
I want to use the
Cisco group. And now I will use the keyword tasks. This is how you can define WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
Cisco group. And now I will use the keyword tasks. This is how you can define
to Ansible
the things that you actually want to do. So the first task I will do, I will
give a name.
And I'll just say send NTP config to the device. When you happen to talk to an
old skill,
Cisco device, you have very particular commands. Say, for example, you want to
make a configuration change.
First, you have to do enable to elevate privileges. And then you will then say,
configure terminal. And it's inside this particular mode that you make
configuration changes.
If you type these particular commands, say, for example, on a Juniper device, WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
If you type these particular commands, say, for example, on a Juniper device,
then the Juniper
device would just be very confused and spit out an error. So what this means is
that with respect
to Ansible, we want to tell Ansible which type of device we're talking to. So
Ansible knows to
type these commands. So the cool thing is, is Ansible actually has a whole
bunch of different
modules. So if you happen to search for Cisco Ansible modules, let's click this
link right here,
Cisco iOS. Now down below here, we actually get a module index. If you want to
particularly
configure, say, for example, iOS ACLs, will you have a module for that? If you WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
configure, say, for example, iOS ACLs, will you have a module for that? If you
want to configure BGP,
you've got a module for that. This is a generic one that allows us to run any
particular command that we
want for configuration changes. So let's click on this right here. And it says
here, this is not
going to be installed by default on Ansible. So what I can do is use this
particular command to
actually install it. So I'll go back to my terminal, paste this command in if I
enter, we're going to
begin installing these Cisco iOS module for Ansible. And we can see here it was
successfully installed. WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
successfully installed.
Now if you happen to go to the documentation, it's going to give you a synopsis
about what this
particular module is going to do, how to actually use it, although particular
values you supply.
In my case here, though, what I want to use is this keyword here, lines. This
is going to allow me to
specify the set of commands that I want to be configured in the section. So let
me show you how this
works then. If I go back here, and I just give the name of the module by saying
Cisco iOS, and this
particular module is iOS underscore config. See it right here. This is what we
're referencing. And
now we're going to reference this lines keyword to specify the commands that I WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
now we're going to reference this lines keyword to specify the commands that I
want to send. So
indented within I will specify lines and then a colon. And again, indented
within I will just specify
the commands that I want to send. Now think about it like this. How would I
actually configure this
on a Cisco device? But if I wanted to make an NTP configuration, I would say N
TP server, and then
specify the IP address of the actual server itself. So in this case here, it
can be 1.1.1.1.1, whatever
it may be. Now remember, do I want to actually hard code this like this? You WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
it may be. Now remember, do I want to actually hard code this like this? You
know, like 1.1.1.1.1?
No, I did not because what's going to happen is I will send this exact command
to all devices in my
inventory marked with the Cisco group. So that means all four devices are going
to get this exact
configuration. We don't want that. We want to use the variable value for this
portion here that is
associated with each devices, variable values in their either host membership
or group membership.
So remember, if we happen to look at this particular value, let's go into the WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
So remember, if we happen to look at this particular value, let's go into the
group wars, for example,
if we go into the UK, the actual key name is NTP_config. So let's actually grab
the key here. So if I
just paste this in and what I'm going to use is some funny syntax, I'm going to
put two curly
braces around the side of it. This is indicating to Ansible Hey, don't actually
type the word NTP
_config, go and look for an associated values in those files and substitute that
in. So for the
devices in the UK, we get this value and for the devices in the USA, we get WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
devices in the UK, we get this value and for the devices in the USA, we get
that value and remember
for device R2 because it's got a host variable that's going to this particular
folder. S2 is actually
got for this particular key, this particular value, which will be rendered. So
if I just save this
right here and what I can do is if I just clear the screen, and the way to tell
Ansible to actually
run a playbook is by saying Ansible, Dash playbook and then just specify the
name of the playbook.
So if I hit Enter, check this out right here. It says we have four changes on WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
So if I hit Enter, check this out right here. It says we have four changes on
four of our devices,
so let's go and check out the results then. So we go to device number one here,
let's open this up.
If I say showrun, section NTP, look at this right here, we have an NTP server
of 1.1.1.1.1.1.
This is exactly the value that was specified in the USA group. See that right
there? However,
remember device number two, if we go and make a connection to this particular
one, let's run
the same command showrun section NTP. This one actually has 8.8.8.8 because the WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
the same command showrun section NTP. This one actually has 8.8.8.8 because the
host membership
is overriding the group membership in this case here. Now we go to the last two
devices S3 and S4,
let's go to S3 first. Again, enable mode will say showrun section NTP. This
time we have configured
the device with 2.2.2.2 for NTP and similarly for device four, which also get
the same result,
let's open this up, go to enable mode showrun section NTP. As we can see here,
all devices have
successfully received the correct configuration and this really highlights the WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
successfully received the correct configuration and this really highlights the
beauty of Ansible.
Just imagine how powerful this would be if we happen to have 1,000 devices in
our network,
been able to easily target subsections of that large network and give them the
configurations
that they need in the blink of an eye. This is going to make your life much
much easier.