WEBVTT

1
00:00.000 --> 00:04.400
Okay friends, so now that we understand how to utilize Ginger2 to do things

2
00:04.400 --> 00:05.600
like variable substitution

3
00:05.600 --> 00:10.640
as well as to create loops and conditional statements, let's now use Ginger2 to

4
00:10.640 --> 00:11.200
actually

5
00:11.200 --> 00:14.280
make a configuration change on our devices.

6
00:14.280 --> 00:17.240
Now the actual configuration that we are going to build is going to be really

7
00:17.240 --> 00:18.160
quite simple.

8
00:18.160 --> 00:22.660
All we're going to do is we're going to change the configurations of our DNS

9
00:22.660 --> 00:23.840
server for each

10
00:23.840 --> 00:25.920
of the devices in our system.

11
00:25.920 --> 00:29.800
So here is what I'm going to do, I'm first going to go to my host variables and

12
00:29.800 --> 00:30.240
let's
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

12
00:29.800 --> 00:30.240
let's

13
00:30.240 --> 00:32.880
go into let's say blue box for example, okay.

14
00:32.880 --> 00:36.240
So inside of here, let me just add the key DNS servers and this is going to be

15
00:36.240 --> 00:36.680
an array

16
00:36.680 --> 00:40.180
object that's going to allow me to specify all of the servers that I want to

17
00:40.180 --> 00:40.680
use.

18
00:40.680 --> 00:45.900
So let's just say we want to use, in this case here, 8.8.8.8, as well as 8.8.4.

19
00:45.900 --> 00:46.320
4.

20
00:46.320 --> 00:48.760
So let's copy it right and quit.

21
00:48.760 --> 00:52.400
And for the yellow box, again, very important, we want to use the same key.

22
00:52.400 --> 00:55.710
So it's going to be DNS servers and then we specify the servers that we want to

23
00:55.710 --> 00:55.960
use.

24
00:55.960 --> 00:59.820
So let's just maybe say this one is going to use 8.8.8.8, as well as let's

25
00:59.820 --> 01:00.120
maybe say
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

25
00:59.820 --> 01:00.120
maybe say

26
01:00.120 --> 01:04.600
1.1.1.1, which I don't believe actually as a DNS server, but nevertheless, it's

27
01:04.600 --> 01:04.840
just

28
01:04.840 --> 01:06.280
for a demonstration.

29
01:06.280 --> 01:10.260
So what we want to do is we want to create a template that is going to make

30
01:10.260 --> 01:11.520
that configuration

31
01:11.520 --> 01:12.520
change.

32
01:12.520 --> 01:14.280
So go into our templates directory.

33
01:14.280 --> 01:15.480
Okay, here we are.

34
01:15.480 --> 01:20.120
And I'm going to create a new template just called, let's just say DNS dot j2.

35
01:20.120 --> 01:21.120
Okay.

36
01:21.120 --> 01:23.440
So what is the base template going to look like?

37
01:23.440 --> 01:26.400
Well, think about what file are we going to try to modify?

38
01:26.400 --> 01:30.900
In this case here, I'm going to try to modify the 8.8.8. resolve.conf
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

38
01:26.400 --> 01:30.900
In this case here, I'm going to try to modify the 8.8.8. resolve.conf

39
01:30.900 --> 01:31.640
configuration file.

40
01:31.640 --> 01:33.440
So let's go and look at that for reference.

41
01:33.440 --> 01:37.200
I will just say cat, 8.8. resolve.conf.

42
01:37.200 --> 01:38.840
And this is the file right here.

43
01:38.840 --> 01:39.840
Now think about it.

44
01:39.840 --> 01:43.480
What would we do if we wanted to have multiple deformed servers?

45
01:43.480 --> 01:47.840
So the way we'd actually modify this, we could say sudo vim, 8.8. resolve.conf.

46
01:47.840 --> 01:50.860
Going to insert more than again, this is not necessarily the way we'd want to

47
01:50.860 --> 01:51.080
do this.

48
01:51.080 --> 01:52.320
It's just for demonstration.

49
01:52.320 --> 01:54.320
You can manage this directly via network manager.

50
01:54.320 --> 01:58.270
And if you want to add in another server, i.e. we have multiple servers, we

51
01:58.270 --> 01:59.240
would say,

52
01:59.240 --> 02:04.000
name server once again, and then specify the corresponding server configuration
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

52
01:59.240 --> 02:04.000
name server once again, and then specify the corresponding server configuration

53
02:04.000 --> 02:04.240
, which

54
02:04.240 --> 02:06.780
would be in this case here, maybe a 1.1.1.1.

55
02:06.780 --> 02:08.960
So basically, imagine this as a template.

56
02:08.960 --> 02:10.240
Okay, let's copy this here.

57
02:10.240 --> 02:12.200
And we'll go to our templates right here.

58
02:12.200 --> 02:13.440
So let's paste this in.

59
02:13.440 --> 02:18.650
Now, let's just go back to this right here in our press escape colon quits and

60
02:18.650 --> 02:19.480
exclamation

61
02:19.480 --> 02:20.480
mark.

62
02:20.480 --> 02:21.480
We don't want to write those changes.

63
02:21.480 --> 02:23.480
Let's just tap this to ensure that there's nothing being changed.

64
02:23.480 --> 02:25.960
We can see we didn't actually modify anything.

65
02:25.960 --> 02:27.280
Now think about this.

66
02:27.280 --> 02:31.750
When we happen to push our rendered configuration, let's just leave this part
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

66
02:27.280 --> 02:31.750
When we happen to push our rendered configuration, let's just leave this part

67
02:31.750 --> 02:32.920
here at the top.

68
02:32.920 --> 02:36.520
That is the comment generated by network manager and search local domain.

69
02:36.520 --> 02:37.520
Let's just leave that.

70
02:37.520 --> 02:38.520
Okay.

71
02:38.520 --> 02:40.920
So we'll just hard code that directly into our template.

72
02:40.920 --> 02:44.280
Now this part here, we see the same thing repeating twice.

73
02:44.280 --> 02:47.360
If we see a repetition, this is a candidate for a loop.

74
02:47.360 --> 02:49.040
So we're going to invoke a loop.

75
02:49.040 --> 02:53.560
And within that loop, we want to hard code the word name server followed by a

76
02:53.560 --> 02:54.240
variable

77
02:54.240 --> 02:57.950
value, which will actually denote the IP address configuration of the name

78
02:57.950 --> 02:58.760
server and we'll

79
02:58.760 --> 03:01.960
call that directly from our host variable file.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

79
02:58.760 --> 03:01.960
call that directly from our host variable file.

80
03:01.960 --> 03:05.160
So basically, we want a loop and within that loop, a variable.

81
03:05.160 --> 03:06.160
Okay.

82
03:06.160 --> 03:10.200
So let's actually try to modify this and insert mode and let's use our loop.

83
03:10.200 --> 03:11.200
Okay.

84
03:11.200 --> 03:15.250
So color brace percentage same and I'll just say for server, again, call this

85
03:15.250 --> 03:15.840
anything

86
03:15.840 --> 03:19.880
you so wish it's just a variable value in and what is the actual key here?

87
03:19.880 --> 03:20.880
Okay.

88
03:20.880 --> 03:24.320
So we can see here the key to be of use is DNS underscore servers.

89
03:24.320 --> 03:25.520
We're going to have to reference that.

90
03:25.520 --> 03:26.520
Okay.

91
03:26.520 --> 03:30.980
So DNS underscore servers and then percentage color brace that gives us our for
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

91
03:26.520 --> 03:30.980
So DNS underscore servers and then percentage color brace that gives us our for

92
03:30.980 --> 03:31.400
loop.

93
03:31.400 --> 03:33.440
Now let me delete this low entry.

94
03:33.440 --> 03:36.420
And like I say, the name server, we're going to leave that word hard coded, but

95
03:36.420 --> 03:36.880
the actual

96
03:36.880 --> 03:39.280
value here, this is going to vary.

97
03:39.280 --> 03:41.320
So how do we actually access the variable?

98
03:41.320 --> 03:43.240
We'll just say double color brace.

99
03:43.240 --> 03:46.750
And all we need to do here is use the variable server because that's going to

100
03:46.750 --> 03:47.240
give us each

101
03:47.240 --> 03:51.120
element within the array, ie each IP address.

102
03:51.120 --> 03:52.560
Now what are we actually missing here?

103
03:52.560 --> 03:54.560
We have started a for loop.

104
03:54.560 --> 03:56.840
Therefore, we're going to have to close it.

105
03:56.840 --> 04:01.720
So we'll say color brace percent and four percent color brace.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

105
03:56.840 --> 04:01.720
So we'll say color brace percent and four percent color brace.

106
04:01.720 --> 04:07.120
So if I press escape colon wq, now we have the DNS dot J2.

107
04:07.120 --> 04:08.120
Okay.

108
04:08.120 --> 04:09.120
So let's go and check this out.

109
04:09.120 --> 04:12.920
Then let's go and I'll just copy over my playbook and let's just call this or

110
04:12.920 --> 04:13.200
render

111
04:13.200 --> 04:14.200
to dot yml.

112
04:14.200 --> 04:15.200
Okay.

113
04:15.200 --> 04:16.880
So let's go in here and modify it.

114
04:16.880 --> 04:20.800
So the source this time is not going to be test dot J2.

115
04:20.800 --> 04:22.360
That is not the template we want.

116
04:22.360 --> 04:25.280
The template we want this time is going to be DNS dot J2.

117
04:25.280 --> 04:28.930
Now that is the file that we're going to render, but where do we actually want

118
04:28.930 --> 04:29.400
to place

119
04:29.400 --> 04:30.400
that file?
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

119
04:29.400 --> 04:30.400
that file?

120
04:30.400 --> 04:33.640
Well, in the destination parameter, we want to specify that this should go into

121
04:33.640 --> 04:34.560
the Etsy

122
04:34.560 --> 04:36.760
resolve dot conf file.

123
04:36.760 --> 04:41.440
So if I just escape colon, write and quit, clear the screen and just say Ans

124
04:41.440 --> 04:42.280
ible hyphen

125
04:42.280 --> 04:46.300
playbook and also render to and enter and we can see the changes have been

126
04:46.300 --> 04:46.920
applied.

127
04:46.920 --> 04:48.200
So let's go to each device.

128
04:48.200 --> 04:53.280
So if I go to the yellow box and I just say vim, it's a resolve dot conf.

129
04:53.280 --> 04:54.280
Look at this right here.

130
04:54.280 --> 04:57.820
The yellow box has the configuration name server, eight dot eight dot eight dot

131
04:57.820 --> 04:58.160
eight

132
04:58.160 --> 05:03.110
and name server one dot one dot one dot one just as we saw within the variable
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

132
04:58.160 --> 05:03.110
and name server one dot one dot one dot one just as we saw within the variable

133
05:03.110 --> 05:03.840
files for

134
05:03.840 --> 05:05.440
that particular host.

135
05:05.440 --> 05:09.960
Now if we go to the blue box and say vim, it's a resolve dot conf.

136
05:09.960 --> 05:13.310
Look at this right here, we see name server eight dot eight dot eight dot eight

137
05:13.310 --> 05:13.920
and name

138
05:13.920 --> 05:18.150
server eight dot eight dot four dot four again, exactly mirroring the

139
05:18.150 --> 05:19.080
configurations that we

140
05:19.080 --> 05:21.920
have for the host variables for that particular device.
