WEBVTT

1
00:00.000 --> 00:05.000
Now here is the thing, automation is super super powerful.

2
00:05.000 --> 00:09.360
So much so that when you happen to be making a very large change across many

3
00:09.360 --> 00:11.000
devices in your network,

4
00:11.000 --> 00:15.000
you might be a little intimidated to actually go through with the change.

5
00:15.000 --> 00:18.450
Because wealth automation can really support charge your ability to make

6
00:18.450 --> 00:20.000
changes and manage your devices,

7
00:20.000 --> 00:25.180
it can also support charge your ability to completely wreck the network and

8
00:25.180 --> 00:27.000
cripple all the devices in that network.

9
00:27.000 --> 00:32.130
This is just a reality of automation. If you happen to construct an erroneous
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

9
00:27.000 --> 00:32.130
This is just a reality of automation. If you happen to construct an erroneous

10
00:32.130 --> 00:34.000
configuration and you suddenly,

11
00:34.000 --> 00:37.900
via automation, push that change out to 1000 devices as opposed to just one

12
00:37.900 --> 00:39.000
device sequentially.

13
00:39.000 --> 00:43.000
Well, quite obviously the consequences are a lot larger.

14
00:43.000 --> 00:48.140
So wouldn't it be cool if we could actually check the effect that our

15
00:48.140 --> 00:49.000
particular change was going to make

16
00:49.000 --> 00:53.000
on our devices without actually touching those devices.

17
00:53.000 --> 00:57.000
Now the good news is that this is one of the things that we can do with Ansible

18
00:57.000 --> 00:57.000
.

19
00:57.000 --> 01:01.000
Now what I should say is that this is not an absolute full proof solution.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

19
00:57.000 --> 01:01.000
Now what I should say is that this is not an absolute full proof solution.

20
01:01.000 --> 01:05.000
There are some caveats, but we will talk about it within this particular video.

21
01:05.000 --> 01:09.270
So with that said, let's dive in and see how we can check our automation

22
01:09.270 --> 01:11.000
solutions before pushing the changes out

23
01:11.000 --> 01:13.000
to our devices for real.

24
01:13.000 --> 01:17.000
Okay, so let me just create a playbook called play2.yml going to insert mode.

25
01:17.000 --> 01:20.000
Let's have our three hyphens at the top, give the playbook a name.

26
01:20.000 --> 01:23.000
And I'll just call this play2 checking changes.

27
01:23.000 --> 01:27.000
Let's target the hosts of the, let's go to blue box again for simplicity.

28
01:27.000 --> 01:30.000
And we'll set gather facts to the value false.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

29
01:30.000 --> 01:31.000
So let's define our tasks.

30
01:31.000 --> 01:34.000
So let's say I want to install engine X.

31
01:34.000 --> 01:38.000
So what I will do is I will use the Ansible built in DNF module.

32
01:38.000 --> 01:43.000
And let's specify that I want to have engine X installed on my target device.

33
01:43.000 --> 01:47.000
So I'll say the state should be present on device.

34
01:47.000 --> 01:51.350
Now right now if I go to my blue box device and I say systemctl status on

35
01:51.350 --> 01:52.000
engine X.

36
01:52.000 --> 01:56.000
We can actually see here that I don't have engine X on this system.

37
01:56.000 --> 02:01.340
Now if I happen to run this playbook as it stands right now ordinarily, what
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

37
01:56.000 --> 02:01.340
Now if I happen to run this playbook as it stands right now ordinarily, what

38
02:01.340 --> 02:07.000
would happen is that because Ansible notices that the engine X7 is not present,

39
02:07.000 --> 02:11.040
then it will begin installing the engine X package to ensure that it is present

40
02:11.040 --> 02:12.000
on the system.

41
02:12.000 --> 02:16.620
So what I will do here is as opposed to running it as I ordinarily would write

42
02:16.620 --> 02:17.000
here,

43
02:17.000 --> 02:21.430
I can invoke check mode by saying dash dash check on the command line right

44
02:21.430 --> 02:22.000
here.

45
02:22.000 --> 02:23.000
Watch what happens now.

46
02:23.000 --> 02:24.000
Okay, so let's hit enter.

47
02:24.000 --> 02:26.000
It actually simulates what would happen.

48
02:26.000 --> 02:29.000
So it tells us a change would be made on the system.

49
02:29.000 --> 02:33.270
But if I go to my blue box here and I rerun the command that systemctl status
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

49
02:29.000 --> 02:33.270
But if I go to my blue box here and I rerun the command that systemctl status

50
02:33.270 --> 02:34.000
on engine X,

51
02:34.000 --> 02:37.000
it still says that the engine X service cannot be found.

52
02:37.000 --> 02:39.000
It wasn't actually applied.

53
02:39.000 --> 02:43.000
But if I run it and remove the check parameter here and to enter,

54
02:43.000 --> 02:46.400
it looks like we have the exact same output, but because we didn't run it in

55
02:46.400 --> 02:47.000
check mode,

56
02:47.000 --> 02:51.000
if I go to my device right here and check the command once again,

57
02:51.000 --> 02:53.000
now we can see here the system is indeed installed.

58
02:53.000 --> 02:54.000
So think about it now.

59
02:54.000 --> 02:57.000
Engine X is installed on a target device.

60
02:57.000 --> 03:00.590
However, let's say weeks past and I didn't actually know if it was installed or
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

60
02:57.000 --> 03:00.590
However, let's say weeks past and I didn't actually know if it was installed or

61
03:00.590 --> 03:01.000
not.

62
03:01.000 --> 03:04.420
If I just happened to run this particular playbook, which checks that it should

63
03:04.420 --> 03:06.000
be present,

64
03:06.000 --> 03:10.000
but it run effectively in simulation mode and check mode that is.

65
03:10.000 --> 03:14.670
And to enter the check mode this time actually says that no changes would be

66
03:14.670 --> 03:15.000
made.

67
03:15.000 --> 03:19.000
So now we can actually logically infer via simulation that the playbook,

68
03:19.000 --> 03:22.000
if it would not actually change anything in the playbook,

69
03:22.000 --> 03:26.000
it's designed to ensure that engine X is installed on the system.

70
03:26.000 --> 03:29.000
Then without the danger of potentially making any changes on the system,

71
03:29.000 --> 03:34.330
because it is purely a simulation, we can actually infer that the package must
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

71
03:29.000 --> 03:34.330
because it is purely a simulation, we can actually infer that the package must

72
03:34.330 --> 03:35.000
actually be

73
03:35.000 --> 03:37.000
installed on the system as it is right now.

74
03:37.000 --> 03:38.000
Really, really handy.

75
03:38.000 --> 03:43.000
Now also what we can do is let's maybe say we wanted to maybe update a

76
03:43.000 --> 03:44.000
configuration file, okay?

77
03:44.000 --> 03:47.450
So if I go into my templates directory right here and I'll just create a little

78
03:47.450 --> 03:49.000
playbook or rather,

79
03:49.000 --> 03:53.000
rather should I say a ginger to a template and I'll just call this example.j2.

80
03:53.000 --> 03:56.000
Let's just say this template is going to say hey friends,

81
03:56.000 --> 04:00.000
and I'll say my name is, and I'll just pass in the variable name, okay?
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

82
04:00.000 --> 04:03.000
So super, super simple template we have right here, okay?

83
04:03.000 --> 04:07.000
Now let's go back and I'll go into a playbook three right here,

84
04:07.000 --> 04:10.000
or rather create playbook three should I say.

85
04:10.000 --> 04:12.000
And again, we'll do our usual three hyphens,

86
04:12.000 --> 04:15.000
playbook three can be checking config changes.

87
04:15.000 --> 04:18.000
Again, we'll target this one device, although you can do two,

88
04:18.000 --> 04:21.560
if you still wish, we'll have gather facts to be false, and now we define our

89
04:21.560 --> 04:22.000
tasks.

90
04:22.000 --> 04:27.000
And I'll give this task your name saying push configs using templates.

91
04:27.000 --> 04:30.000
So I'm going to use the Ansible built-in template module this time,
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

92
04:30.000 --> 04:35.000
and now I'm going to specify that the source is going to be example.j2,

93
04:35.000 --> 04:36.000
and the destination.

94
04:36.000 --> 04:40.000
I, where do I want the file to be copied on the target device?

95
04:40.000 --> 04:44.000
I will just have it in the 10th directory, and I'll just call the message

96
04:44.000 --> 04:46.000
greeting.txt, okay?

97
04:46.000 --> 04:49.470
So what I'm going to do here is I actually want to define this particular

98
04:49.470 --> 04:50.000
variable name.

99
04:50.000 --> 04:53.000
So I'm going to my host files right here, and I'll go into the playbook,

100
04:53.000 --> 04:57.000
and I'll give the name of let's go with John, okay?

101
04:57.000 --> 05:01.000
So check this out, if I go back, and I run my little playbook right here,
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

101
04:57.000 --> 05:01.000
So check this out, if I go back, and I run my little playbook right here,

102
05:01.000 --> 05:05.000
and again, I just run it in check modes, it tells me that if I run this,

103
05:05.000 --> 05:09.460
a change would be made on the system, but right now it's not given me that much

104
05:09.460 --> 05:10.000
information,

105
05:10.000 --> 05:14.280
and again, just for proof, if I do an LS, notice the greeting file was not

106
05:14.280 --> 05:15.000
actually created,

107
05:15.000 --> 05:16.000
just merely simulated.

108
05:16.000 --> 05:21.520
So this time, if we happen to make a change here, and this time we run it for

109
05:21.520 --> 05:22.000
real,

110
05:22.000 --> 05:25.670
give it a moment, it looks like we have the same thing, a change should be

111
05:25.670 --> 05:26.000
applied,

112
05:26.000 --> 05:29.000
but this time, the change actually was applied, okay?

113
05:29.000 --> 05:31.000
So we do have the greeting right here.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

113
05:29.000 --> 05:31.000
So we do have the greeting right here.

114
05:31.000 --> 05:33.000
Now, this is not the interesting part that I want to show you,

115
05:33.000 --> 05:37.000
I want to show you an additional flag that we can use here, and personally,

116
05:37.000 --> 05:39.000
this is one I really love.

117
05:39.000 --> 05:43.000
So let's maybe say I happen to make the modification of the variable itself,

118
05:43.000 --> 05:44.000
okay?

119
05:44.000 --> 05:49.000
So let's go into blue box, and I'll change my name here to be Simone, okay?

120
05:49.000 --> 05:54.000
Now let's go back, if I happen to run the playbook and check mode again here,

121
05:54.000 --> 05:59.000
it shows us a change would actually be made because that is a change within the

122
05:59.000 --> 05:59.000
render

123
05:59.000 --> 06:03.000
template now, the name has changed within the templates, but the cool thing is,
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

123
05:59.000 --> 06:03.000
template now, the name has changed within the templates, but the cool thing is,

124
06:03.000 --> 06:06.000
if I want to see what the change actually would be versus what it is right now,

125
06:06.000 --> 06:11.000
I.e. what the difference would be, if I run this playbook, I can say dash dash,

126
06:11.000 --> 06:13.000
def with my check command.

127
06:13.000 --> 06:16.000
So let's hit enter here, and look at this, we get this summary right here,

128
06:16.000 --> 06:20.000
it says if we happen to run this particular file, or rather this particular

129
06:20.000 --> 06:21.000
playbook,

130
06:21.000 --> 06:25.000
the net effect would be we would keep this particular line here,

131
06:25.000 --> 06:29.000
that would stay the same, hey friends, but this line here, my name is German,

132
06:29.000 --> 06:34.000
no longer exists, it would be replaced with this line here, my name is Simone,
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

132
06:29.000 --> 06:34.000
no longer exists, it would be replaced with this line here, my name is Simone,

133
06:34.000 --> 06:38.000
so imagine you happen to have some complex configurations, maybe a whole bunch

134
06:38.000 --> 06:39.000
of DNS servers

135
06:39.000 --> 06:43.000
specified within a configuration file that you're rendering, you can

136
06:43.000 --> 06:43.000
effectively see

137
06:43.000 --> 06:48.000
what changes you are going to make via the automation system before you apply

138
06:48.000 --> 06:49.000
them for real.

139
06:49.000 --> 06:53.000
So again, like I say, if I go to my device and I can't the file, the change

140
06:53.000 --> 06:53.000
hasn't

141
06:53.000 --> 06:57.000
actually been applied yet, however, I have simulated the change and I see here

142
06:57.000 --> 07:01.000
that I'm happy that I want the fail to change, and instead to read my name as
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

142
06:57.000 --> 07:01.000
that I'm happy that I want the fail to change, and instead to read my name as

143
07:01.000 --> 07:04.000
Simone, so what I will do now is because I know what the change is going to be,

144
07:04.000 --> 07:07.000
I just run the playbook for real.

145
07:07.000 --> 07:11.000
So now the change will actually be applied, I go to my device, let's cat this,

146
07:11.000 --> 07:14.000
look at this right here, now we see the actual change that was simulated

147
07:14.000 --> 07:15.000
beforehand,

148
07:15.000 --> 07:19.000
and again, if I run check mode once again with the diff,

149
07:19.000 --> 07:23.000
because the render template is no longer going to make a change,

150
07:23.000 --> 07:26.000
look at this right here, it simulates that there would be no changes made,

151
07:26.000 --> 07:30.000
we're getting to see the item importance of the actual module itself here.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

152
07:30.000 --> 07:33.700
So if we change the variable, we can see the change, but also if we go and

153
07:33.700 --> 07:34.000
modify the

154
07:34.000 --> 07:37.710
template itself and perhaps maybe add in an additional line, let's just imagine

155
07:37.710 --> 07:38.000
we were

156
07:38.000 --> 07:43.000
adding in a DNS server, okay, we'll just say DNS server one, two, three, four,

157
07:43.000 --> 07:43.000
okay,

158
07:43.000 --> 07:45.000
whatever, it doesn't actually matter the change.

159
07:45.000 --> 07:50.000
If I now re-run the simulation once again, it tells us a change would actually

160
07:50.000 --> 07:51.000
be made,

161
07:51.000 --> 07:55.000
and it tells us we would have an additional line of DNS server one, two, three,

162
07:55.000 --> 07:55.000
four.

163
07:55.000 --> 07:59.390
Now one thing just to be aware of, with respect to your playbooks, you may

164
07:59.390 --> 08:00.000
actually have
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

165
08:00.000 --> 08:05.170
some conditionals that do require particular changes to actually be running on

166
08:05.170 --> 08:06.000
the system

167
08:06.000 --> 08:10.000
in order for a particular task to execute, you may make an actual change,

168
08:10.000 --> 08:14.000
and if the answerable system detects that change on the live system,

169
08:14.000 --> 08:17.560
then another task might execute, perhaps you're running a handler, that type of

170
08:17.560 --> 08:18.000
thing.

171
08:18.000 --> 08:23.420
However, because of this, the nature of the simulation, because it won't really

172
08:23.420 --> 08:24.000
make that

173
08:24.000 --> 08:27.000
change, it might give you an erroneous output.

174
08:27.000 --> 08:30.000
So well as this can be very, very effective, understand the limitations,
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

175
08:30.000 --> 08:35.000
be very aware that when you use conditionals, not all the output is going to be

176
08:35.000 --> 08:36.000
100% accurate,

177
08:36.000 --> 08:39.000
so still proceed with caution is what I'm saying here.

178
08:39.000 --> 08:44.240
So just with respect to our check mode, we can actually run check mode on a

179
08:44.240 --> 08:45.000
particular task,

180
08:45.000 --> 08:47.000
as opposed to the entire playbook.

181
08:47.000 --> 08:52.050
So if I go in to my playbook right here, if I just happen to specify that this

182
08:52.050 --> 08:53.000
particular task

183
08:53.000 --> 08:59.130
has check_mode set to the value of yes, and let's do one similar here okay, let

184
08:59.130 --> 09:00.000
's create another task,
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

185
09:00.000 --> 09:03.600
in order to push other conflicts using template, and again I'll do something

186
09:03.600 --> 09:04.000
very similar.

187
09:04.000 --> 09:09.000
Let's use another template called example2.j2, the destination is going to be

188
09:09.000 --> 09:09.000
temp,

189
09:09.000 --> 09:12.000
and just call us one another greeting.txt.

190
09:12.000 --> 09:17.220
Notice this one here has to check mode enabled for this particular task, and

191
09:17.220 --> 09:18.000
this one does not.

192
09:18.000 --> 09:21.390
All I'm going to do here very briefly is I'll go into my templates again, and I

193
09:21.390 --> 09:24.000
'll create a file called example2.j2,

194
09:24.000 --> 09:30.000
go into insert mode, order save bonjour, as another greeting, hello from name.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

195
09:30.000 --> 09:33.000
Okay, so let's save this right here, and if I go back, and all I will do is I

196
09:33.000 --> 09:33.000
'll go into the

197
09:33.000 --> 09:37.680
host files again, and all I will do is I'll update the name, this time to be

198
09:37.680 --> 09:39.000
James, okay, so let's save this.

199
09:39.000 --> 09:43.510
So if I happen to run the playbook right here, and to enter, we can see here

200
09:43.510 --> 09:45.000
the two tasks apparently have

201
09:45.000 --> 09:49.680
operated, which should mean that the greeting.txt here, that file should be

202
09:49.680 --> 09:52.000
updated to reflect the change of

203
09:52.000 --> 09:56.250
James. However, when I count the greeting file, notice it still is Samona, it

204
09:56.250 --> 09:58.000
was ran in check mode,

205
09:58.000 --> 10:02.300
however, the other task, which was not configured to run as check mode, that
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

205
09:58.000 --> 10:02.300
however, the other task, which was not configured to run as check mode, that

206
10:02.300 --> 10:03.000
did run for real to be really

207
10:03.000 --> 10:08.730
should have an example to .j2 rendering, creating the file, another greeting.

208
10:08.730 --> 10:09.000
txt.

209
10:09.000 --> 10:13.440
So do an LS, notice we do have this particular file, another greeting, so let's

210
10:13.440 --> 10:14.000
cut this.

211
10:14.000 --> 10:18.320
Look at this right here, this particular change was indeed applied to the live

212
10:18.320 --> 10:19.000
system.
