WEBVTT

1
00:00.000 --> 00:04.410
So friends, in this particular video, what I want to do is to talk to you about

2
00:04.410 --> 00:04.960
a very

3
00:04.960 --> 00:09.920
particular module that we can use when implementing our Ginger 2 templates.

4
00:09.920 --> 00:11.640
That is the template module.

5
00:11.640 --> 00:14.000
With that said, let's just check it out.

6
00:14.000 --> 00:15.800
So you already know what I'm going to do.

7
00:15.800 --> 00:17.440
Let's go to the big Google machine.

8
00:17.440 --> 00:21.320
So if you just happened to search for Ansible template module, let's go to this

9
00:21.320 --> 00:21.720
top link

10
00:21.720 --> 00:24.320
right here, template of file out to a target host.

11
00:24.320 --> 00:27.890
So the very first thing to note is that this is part of Ansible Core, meaning

12
00:27.890 --> 00:28.560
that we do

13
00:28.560 --> 00:31.680
not have to do any type of additional installation.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

13
00:28.560 --> 00:31.680
not have to do any type of additional installation.

14
00:31.680 --> 00:34.360
This is going to be with us directly out the box.

15
00:34.360 --> 00:38.560
Now realistically, we can use the short name templates, but preferably I tend

16
00:38.560 --> 00:39.160
to be very,

17
00:39.160 --> 00:40.160
very explicit.

18
00:40.160 --> 00:43.680
And just like with the shell module, for example, I like to say Ansible dot

19
00:43.680 --> 00:45.000
built in dot template

20
00:45.000 --> 00:49.430
when using this particular file, or rather using this particular module, should

21
00:49.430 --> 00:49.920
I say.

22
00:49.920 --> 00:52.600
Like you see, it's just to avoid conflicting with any other collections.

23
00:52.600 --> 00:53.600
Okay.

24
00:53.600 --> 00:57.280
So with that said, let's just scroll on down and see how this actually operates

25
00:57.280 --> 00:57.760
them.

26
00:57.760 --> 01:01.400
So as we're going to see when we dig into the actual use of Ginger 2, the
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

26
00:57.760 --> 01:01.400
So as we're going to see when we dig into the actual use of Ginger 2, the

27
01:01.400 --> 01:01.840
templates are

28
01:01.840 --> 01:05.560
going to be processed by the Ginger 2 temperature language.

29
01:05.560 --> 01:08.640
And if we scroll on down, we come to the actual parameters of play.

30
01:08.640 --> 01:12.850
Now we see here we actually have this option for block end string, as well as

31
01:12.850 --> 01:13.600
block start

32
01:13.600 --> 01:14.600
string.

33
01:14.600 --> 01:15.600
Notice the actual syntax here.

34
01:15.600 --> 01:16.600
Okay.

35
01:16.600 --> 01:20.000
What we actually have here is a curly brace followed by a percentage sign.

36
01:20.000 --> 01:23.560
Now this is the type of formatting we're going to see when we come to use

37
01:23.560 --> 01:24.280
Ginger 2.

38
01:24.280 --> 01:27.920
So just understand that this is the default setting and we can actually use a

39
01:27.920 --> 01:28.480
different

40
01:28.480 --> 01:32.200
delimiter if we so wish by specifying particular parameters.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

40
01:28.480 --> 01:32.200
delimiter if we so wish by specifying particular parameters.

41
01:32.200 --> 01:36.600
So whilst we will be using this particular syntax in our Ginger templates, just

42
01:36.600 --> 01:37.160
understand

43
01:37.160 --> 01:39.440
we can actually have some variation on this.

44
01:39.440 --> 01:40.440
Okay.

45
01:40.440 --> 01:42.600
Now this particular option here is very, very important.

46
01:42.600 --> 01:43.600
How's important?

47
01:43.600 --> 01:46.360
Well, we can tell because it says it is required.

48
01:46.360 --> 01:50.090
What this is actually going to do, it's going to allow to specify the

49
01:50.090 --> 01:51.560
destination pass pretty

50
01:51.560 --> 01:56.840
much when we actually render our Ginger 2 templates, we can define where about

51
01:56.840 --> 01:57.400
we want

52
01:57.400 --> 02:00.720
the finalize render template to actually be.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

52
01:57.400 --> 02:00.720
the finalize render template to actually be.

53
02:00.720 --> 02:01.920
So what does that actually mean?

54
02:01.920 --> 02:04.600
Well, imagine you happen to have your Ansible machine right here.

55
02:04.600 --> 02:08.820
And let's maybe say we are managing three different servers with Ansible and we

56
02:08.820 --> 02:09.120
want

57
02:09.120 --> 02:13.920
to push out some type of templateized configurations to these three devices.

58
02:13.920 --> 02:16.840
Well, where about do we actually want the configurations to go?

59
02:16.840 --> 02:18.040
Where is the destination?

60
02:18.040 --> 02:22.900
So let's maybe say we wanted to template out the Etsy host file for each device

61
02:22.900 --> 02:23.200
.

62
02:23.200 --> 02:26.270
Well, that would actually be the destination that we would supply here and that

63
02:26.270 --> 02:27.320
would copy

64
02:27.320 --> 02:31.550
the configurations we render here into that particular file on this device, the
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

64
02:27.320 --> 02:31.550
the configurations we render here into that particular file on this device, the

65
02:31.550 --> 02:31.920
second

66
02:31.920 --> 02:34.960
device and the third device right here as per the diagram.

67
02:34.960 --> 02:37.480
So very, very important parameter to understand.

68
02:37.480 --> 02:41.790
Now scrolling on down here, we come to another very, very important parameter,

69
02:41.790 --> 02:43.040
the SRC parameter.

70
02:43.040 --> 02:46.200
This is going to allow us to specify the source in this case.

71
02:46.200 --> 02:50.800
And once again, we can see here that this is actually a required parameter for

72
02:50.800 --> 02:51.400
this particular

73
02:51.400 --> 02:52.400
module.

74
02:52.400 --> 02:56.060
So using the previous example, if we happen to have our Ansible controller here

75
02:56.060 --> 02:56.360
and our

76
02:56.360 --> 03:01.010
three devices that we happen to be managing, if we are modifying the Etsy host
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

76
02:56.360 --> 03:01.010
three devices that we happen to be managing, if we are modifying the Etsy host

77
03:01.010 --> 03:01.800
file, that

78
03:01.800 --> 03:04.640
would be the destination that we specify.

79
03:04.640 --> 03:08.120
And that is going to be applied to the actual managed devices here.

80
03:08.120 --> 03:12.870
Whereas the source parameter that actually applies to the Ansible host itself,

81
03:12.870 --> 03:13.120
what we

82
03:13.120 --> 03:18.250
are actually referring to is whereabouts the actual gender to template can be

83
03:18.250 --> 03:18.720
found, the

84
03:18.720 --> 03:22.400
template that is going to render the configurations that will be pushed to

85
03:22.400 --> 03:24.320
these destination endpoints.

86
03:24.320 --> 03:27.470
So if you happen to scroll all the way down to the very bottom here, we can see

87
03:27.470 --> 03:28.280
some examples

88
03:28.280 --> 03:30.960
of utilizing a template.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

88
03:28.280 --> 03:30.960
of utilizing a template.

89
03:30.960 --> 03:34.810
Say for example, here we want to write a template for the Etsy file dot conf

90
03:34.810 --> 03:35.920
configuration file

91
03:35.920 --> 03:36.920
here.

92
03:36.920 --> 03:39.490
We see the name of the task, we can see the actual module being used here with

93
03:39.490 --> 03:39.840
the full

94
03:39.840 --> 03:44.520
name as specified, we see the source and destination because they happen to be

95
03:44.520 --> 03:45.560
required.

96
03:45.560 --> 03:48.980
And notice here, like I say, this is the path to the actual gender template

97
03:48.980 --> 03:49.640
itself on the

98
03:49.640 --> 03:50.720
Ansible device.

99
03:50.720 --> 03:53.200
My templates through dot J2.

100
03:53.200 --> 03:57.040
Now, this is actually common convention to actually have your own sub folder

101
03:57.040 --> 03:57.520
for your

102
03:57.520 --> 03:58.520
templates.

103
03:58.520 --> 04:02.490
You can call anything you so wish like my templates or as I often just do
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

103
03:58.520 --> 04:02.490
You can call anything you so wish like my templates or as I often just do

104
04:02.490 --> 04:02.960
simply just

105
04:02.960 --> 04:06.260
create a file or rather a folder should I say called templates that is going to

106
04:06.260 --> 04:06.560
keep

107
04:06.560 --> 04:09.990
things nice and orderly so that we're not mixing and matching our templates

108
04:09.990 --> 04:10.440
with our

109
04:10.440 --> 04:11.880
variable files, that type of thing.

110
04:11.880 --> 04:15.310
And again, like I said, the destination, we can just supply the path right here

111
04:15.310 --> 04:15.560
.

112
04:15.560 --> 04:18.900
Now, we can also specify additional options such as the owner of the file, the

113
04:18.900 --> 04:19.320
group,

114
04:19.320 --> 04:21.320
as well as the file permissions right here.

115
04:21.320 --> 04:24.920
In this case here, we have 644, which should be the opton notation.

116
04:24.920 --> 04:28.960
But if we go down to the bottom example here, as the source, we render the food

117
04:28.960 --> 04:30.040
dot J2 file
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

117
04:28.960 --> 04:30.040
dot J2 file

118
04:30.040 --> 04:34.560
and copy into the Etsy file dot confell in all the targets.

119
04:34.560 --> 04:39.520
This time though, the mode is allowing us to specify the file permissions

120
04:39.520 --> 04:40.640
utilizing some

121
04:40.640 --> 04:44.530
ball annotation to that obviously as an option to notice that we can also

122
04:44.530 --> 04:45.600
dynamically pass

123
04:45.600 --> 04:48.280
in different source configuration files.

124
04:48.280 --> 04:51.480
And this case here, but actually not hard code in the value, we are calling a

125
04:51.480 --> 04:51.920
variable

126
04:51.920 --> 04:56.000
value contingent upon the Ansible operating system family.

127
04:56.000 --> 04:59.010
This is very, very good when you don't want to be copying the same type of

128
04:59.010 --> 04:59.760
configuration

129
04:59.760 --> 05:01.280
to the same type of device.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

129
04:59.760 --> 05:01.280
to the same type of device.

130
05:01.280 --> 05:05.760
You want to render configurations to a Debian based system and use a different

131
05:05.760 --> 05:06.280
template

132
05:06.280 --> 05:08.880
for a rail based system.

133
05:08.880 --> 05:12.160
Utilizing substitution and calling in these variables allows us to dynamically

134
05:12.160 --> 05:12.480
look up

135
05:12.480 --> 05:16.680
the correct path for the correct type of operating system in this example.

136
05:16.680 --> 05:19.910
So those are just some of the bare bones basics about how to utilize this

137
05:19.910 --> 05:20.840
particular module.

138
05:20.840 --> 05:23.120
But as you know, the best thing to do is to get hands on.

139
05:23.120 --> 05:26.680
So the very first thing that we're going to be doing is to build out some

140
05:26.680 --> 05:27.320
variables

141
05:27.320 --> 05:31.320
and then begin combining those variables with the template module to actual
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

141
05:27.320 --> 05:31.320
and then begin combining those variables with the template module to actual

142
05:31.320 --> 05:32.200
render configurations

143
05:32.200 --> 05:33.840
utilizing JINJITTER.
