WEBVTT

1
00:00.000 --> 00:03.440
So friends, now we have all of the building blocks in place.

2
00:03.440 --> 00:06.880
Let's now begin configuring our very first Ansible Playbook.

3
00:06.880 --> 00:10.800
So if I do a listing, what we can see here is I have my configuration file,

4
00:10.800 --> 00:15.360
I have my inventory file, as well as two folders containing my variables,

5
00:15.360 --> 00:17.840
one for group, the other for host membership.

6
00:17.840 --> 00:20.720
In this particular directory, what I will do is I'll create a Playbook,

7
00:20.720 --> 00:25.200
which is called as Playbook1.yml, and all I will do is open this one up.

8
00:25.200 --> 00:29.280
Now, fair warning, if this is the first time you're seeing an Ansible Playbook,

9
00:29.280 --> 00:32.480
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

9
00:29.280 --> 00:32.480
then there is a chance that it's going to look a little bit confusing.

10
00:32.480 --> 00:36.240
There's no escaping that. That is simply because it's just new to you,

11
00:36.240 --> 00:40.160
and as you get more familiar with Ansible Playbooks, you begin to see it's

12
00:40.160 --> 00:41.440
really the same kind of thing

13
00:41.440 --> 00:44.400
over and over and over again. The structure is really quite similar.

14
00:44.400 --> 00:46.480
So basically trying out to get too intimidated.

15
00:46.480 --> 00:49.680
At the very top, what I'm going to do here is to create a name of the Playbook,

16
00:49.680 --> 00:53.200
and you can call this "N" to use a wish. So I'm going to use the name key,

17
00:53.200 --> 00:55.200
and now I specify my name.

18
00:55.200 --> 00:58.970
Let's just call this "NTP Playbook" because essentially that's what I'm going

19
00:58.970 --> 00:59.520
to do.

20
00:59.520 --> 01:03.520
Now, super, super important. We're going to use this host keyword.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

20
00:59.520 --> 01:03.520
Now, super, super important. We're going to use this host keyword.

21
01:03.520 --> 01:07.760
This is an Ansible convention, and this is how we specify to Ansible which

22
01:07.760 --> 01:13.360
host to be wish to target. So in my case here, I wanted to deploy NTP to all

23
01:13.360 --> 01:14.400
four of my devices.

24
01:14.400 --> 01:17.600
So if we actually think about it, if I look at my inventory,

25
01:17.600 --> 01:22.080
if I specify the Cisco group, well, that is actually going to target all four

26
01:22.080 --> 01:22.800
devices right there.

27
01:22.800 --> 01:26.320
That encompasses all those devices. So this is what I will do. So I'll just say

28
01:26.320 --> 01:27.280
I want to use the

29
01:27.280 --> 01:31.440
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

29
01:27.280 --> 01:31.440
Cisco group. And now I will use the keyword tasks. This is how you can define

30
01:31.440 --> 01:32.080
to Ansible

31
01:32.080 --> 01:36.030
the things that you actually want to do. So the first task I will do, I will

32
01:36.030 --> 01:36.560
give a name.

33
01:36.560 --> 01:42.240
And I'll just say send NTP config to the device. When you happen to talk to an

34
01:42.240 --> 01:42.800
old skill,

35
01:42.800 --> 01:47.350
Cisco device, you have very particular commands. Say, for example, you want to

36
01:47.350 --> 01:48.720
make a configuration change.

37
01:48.720 --> 01:52.160
First, you have to do enable to elevate privileges. And then you will then say,

38
01:52.160 --> 01:56.310
configure terminal. And it's inside this particular mode that you make

39
01:56.310 --> 01:57.920
configuration changes.

40
01:57.920 --> 02:02.330
If you type these particular commands, say, for example, on a Juniper device,
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

40
01:57.920 --> 02:02.330
If you type these particular commands, say, for example, on a Juniper device,

41
02:02.330 --> 02:02.880
then the Juniper

42
02:02.880 --> 02:06.950
device would just be very confused and spit out an error. So what this means is

43
02:06.950 --> 02:07.920
that with respect

44
02:07.920 --> 02:12.660
to Ansible, we want to tell Ansible which type of device we're talking to. So

45
02:12.660 --> 02:13.760
Ansible knows to

46
02:13.760 --> 02:17.090
type these commands. So the cool thing is, is Ansible actually has a whole

47
02:17.090 --> 02:18.000
bunch of different

48
02:18.000 --> 02:22.140
modules. So if you happen to search for Cisco Ansible modules, let's click this

49
02:22.140 --> 02:22.960
link right here,

50
02:22.960 --> 02:27.920
Cisco iOS. Now down below here, we actually get a module index. If you want to

51
02:27.920 --> 02:28.560
particularly

52
02:28.560 --> 02:33.210
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

52
02:28.560 --> 02:33.210
configure, say, for example, iOS ACLs, will you have a module for that? If you

53
02:33.210 --> 02:34.320
want to configure BGP,

54
02:34.320 --> 02:37.840
you've got a module for that. This is a generic one that allows us to run any

55
02:37.840 --> 02:38.880
particular command that we

56
02:38.880 --> 02:43.020
want for configuration changes. So let's click on this right here. And it says

57
02:43.020 --> 02:43.760
here, this is not

58
02:43.760 --> 02:47.960
going to be installed by default on Ansible. So what I can do is use this

59
02:47.960 --> 02:49.440
particular command to

60
02:49.440 --> 02:52.960
actually install it. So I'll go back to my terminal, paste this command in if I

61
02:52.960 --> 02:54.160
enter, we're going to

62
02:54.160 --> 02:58.870
begin installing these Cisco iOS module for Ansible. And we can see here it was

63
02:58.870 --> 03:00.560
successfully installed.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

63
02:58.870 --> 03:00.560
successfully installed.

64
03:00.560 --> 03:03.600
Now if you happen to go to the documentation, it's going to give you a synopsis

65
03:03.600 --> 03:04.320
about what this

66
03:04.320 --> 03:08.190
particular module is going to do, how to actually use it, although particular

67
03:08.190 --> 03:09.520
values you supply.

68
03:09.520 --> 03:13.020
In my case here, though, what I want to use is this keyword here, lines. This

69
03:13.020 --> 03:14.240
is going to allow me to

70
03:14.240 --> 03:18.010
specify the set of commands that I want to be configured in the section. So let

71
03:18.010 --> 03:19.040
me show you how this

72
03:19.040 --> 03:23.430
works then. If I go back here, and I just give the name of the module by saying

73
03:23.430 --> 03:24.560
Cisco iOS, and this

74
03:24.560 --> 03:28.400
particular module is iOS underscore config. See it right here. This is what we

75
03:28.400 --> 03:29.520
're referencing. And

76
03:29.520 --> 03:33.420
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

76
03:29.520 --> 03:33.420
now we're going to reference this lines keyword to specify the commands that I

77
03:33.420 --> 03:34.640
want to send. So

78
03:34.640 --> 03:39.020
indented within I will specify lines and then a colon. And again, indented

79
03:39.020 --> 03:40.560
within I will just specify

80
03:40.560 --> 03:43.540
the commands that I want to send. Now think about it like this. How would I

81
03:43.540 --> 03:44.640
actually configure this

82
03:44.640 --> 03:49.570
on a Cisco device? But if I wanted to make an NTP configuration, I would say N

83
03:49.570 --> 03:50.960
TP server, and then

84
03:50.960 --> 03:54.690
specify the IP address of the actual server itself. So in this case here, it

85
03:54.690 --> 03:56.640
can be 1.1.1.1.1, whatever

86
03:56.640 --> 04:01.070
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

86
03:56.640 --> 04:01.070
it may be. Now remember, do I want to actually hard code this like this? You

87
04:01.070 --> 04:02.960
know, like 1.1.1.1.1?

88
04:02.960 --> 04:08.370
No, I did not because what's going to happen is I will send this exact command

89
04:08.370 --> 04:10.080
to all devices in my

90
04:10.080 --> 04:15.130
inventory marked with the Cisco group. So that means all four devices are going

91
04:15.130 --> 04:16.480
to get this exact

92
04:16.480 --> 04:21.530
configuration. We don't want that. We want to use the variable value for this

93
04:21.530 --> 04:22.720
portion here that is

94
04:22.720 --> 04:27.360
associated with each devices, variable values in their either host membership

95
04:27.360 --> 04:28.800
or group membership.

96
04:28.800 --> 04:32.430
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

96
04:28.800 --> 04:32.430
So remember, if we happen to look at this particular value, let's go into the

97
04:32.430 --> 04:33.920
group wars, for example,

98
04:33.920 --> 04:40.640
if we go into the UK, the actual key name is NTP_config. So let's actually grab

99
04:40.640 --> 04:42.000
the key here. So if I

100
04:42.000 --> 04:46.130
just paste this in and what I'm going to use is some funny syntax, I'm going to

101
04:46.130 --> 04:46.880
put two curly

102
04:46.880 --> 04:51.260
braces around the side of it. This is indicating to Ansible Hey, don't actually

103
04:51.260 --> 04:52.480
type the word NTP

104
04:52.480 --> 04:57.940
_config, go and look for an associated values in those files and substitute that

105
04:57.940 --> 04:58.560
in. So for the

106
04:58.560 --> 05:03.510
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

106
04:58.560 --> 05:03.510
devices in the UK, we get this value and for the devices in the USA, we get

107
05:03.510 --> 05:05.120
that value and remember

108
05:05.120 --> 05:09.620
for device R2 because it's got a host variable that's going to this particular

109
05:09.620 --> 05:10.960
folder. S2 is actually

110
05:10.960 --> 05:15.380
got for this particular key, this particular value, which will be rendered. So

111
05:15.380 --> 05:16.400
if I just save this

112
05:16.400 --> 05:20.190
right here and what I can do is if I just clear the screen, and the way to tell

113
05:20.190 --> 05:21.280
Ansible to actually

114
05:21.280 --> 05:25.410
run a playbook is by saying Ansible, Dash playbook and then just specify the

115
05:25.410 --> 05:26.800
name of the playbook.

116
05:26.800 --> 05:31.360
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

116
05:26.800 --> 05:31.360
So if I hit Enter, check this out right here. It says we have four changes on

117
05:31.360 --> 05:32.320
four of our devices,

118
05:32.320 --> 05:35.520
so let's go and check out the results then. So we go to device number one here,

119
05:35.520 --> 05:36.320
let's open this up.

120
05:36.320 --> 05:42.230
If I say showrun, section NTP, look at this right here, we have an NTP server

121
05:42.230 --> 05:43.840
of 1.1.1.1.1.1.

122
05:43.840 --> 05:48.030
This is exactly the value that was specified in the USA group. See that right

123
05:48.030 --> 05:49.280
there? However,

124
05:49.280 --> 05:53.030
remember device number two, if we go and make a connection to this particular

125
05:53.030 --> 05:54.480
one, let's run

126
05:54.480 --> 06:01.500
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

126
05:54.480 --> 06:01.500
the same command showrun section NTP. This one actually has 8.8.8.8 because the

127
06:01.500 --> 06:02.400
host membership

128
06:02.400 --> 06:06.950
is overriding the group membership in this case here. Now we go to the last two

129
06:06.950 --> 06:08.720
devices S3 and S4,

130
06:08.720 --> 06:14.880
let's go to S3 first. Again, enable mode will say showrun section NTP. This

131
06:14.880 --> 06:16.080
time we have configured

132
06:16.080 --> 06:21.360
the device with 2.2.2.2 for NTP and similarly for device four, which also get

133
06:21.360 --> 06:22.000
the same result,

134
06:22.000 --> 06:27.100
let's open this up, go to enable mode showrun section NTP. As we can see here,

135
06:27.100 --> 06:27.760
all devices have

136
06:27.760 --> 06:32.330
successfully received the correct configuration and this really highlights the
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

136
06:27.760 --> 06:32.330
successfully received the correct configuration and this really highlights the

137
06:32.330 --> 06:33.360
beauty of Ansible.

138
06:33.360 --> 06:38.080
Just imagine how powerful this would be if we happen to have 1,000 devices in

139
06:38.080 --> 06:38.480
our network,

140
06:38.480 --> 06:42.880
been able to easily target subsections of that large network and give them the

141
06:42.880 --> 06:43.440
configurations

142
06:43.440 --> 06:47.580
that they need in the blink of an eye. This is going to make your life much

143
06:47.580 --> 06:48.400
much easier.
