WEBVTT

1
00:00.000 --> 00:04.780
So in the previous video we just discussed the concept of fact gathering. We

2
00:04.780 --> 00:05.280
learned that this

3
00:05.280 --> 00:09.420
could return very important system information such as the architecture of the

4
00:09.420 --> 00:10.400
machine the IP

5
00:10.400 --> 00:13.970
address is configured on the machine MAC addresses that type of thing and we

6
00:13.970 --> 00:14.800
learned that this can

7
00:14.800 --> 00:20.110
be very useful when invoking tasks based on conditional logic. So this is all

8
00:20.110 --> 00:21.600
very fine and well,

9
00:21.600 --> 00:26.840
however the kind of limitation here as it stands is that the facts here may not

10
00:26.840 --> 00:27.680
encompass

11
00:27.680 --> 00:31.540
absolutely everything that you may want to know about a machine. After all
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

11
00:27.680 --> 00:31.540
absolutely everything that you may want to know about a machine. After all

12
00:31.540 --> 00:32.800
these are just common

13
00:32.800 --> 00:37.500
facts that the Ansible developers have deemed to be important but in your case

14
00:37.500 --> 00:38.000
maybe you want

15
00:38.000 --> 00:42.550
to know some more well let's say custom information about your machines how an

16
00:42.550 --> 00:43.840
earth would be solved

17
00:43.840 --> 00:47.600
that problem. Well drumroll please I'm glad you asked what we're going to be

18
00:47.600 --> 00:48.720
talking about in this

19
00:48.720 --> 00:54.240
particular video is the creation of our own custom facts. So the big difference

20
00:54.240 --> 00:55.280
here therefore is

21
00:55.280 --> 01:00.170
that we're not going to have to rely on the facts defined by Ansible we define
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

21
00:55.280 --> 01:00.170
that we're not going to have to rely on the facts defined by Ansible we define

22
01:00.170 --> 01:00.880
the facts that we

23
01:00.880 --> 01:05.830
are interested in and we can have Ansible gather and assimilate all those facts

24
01:05.830 --> 01:07.120
when we run particular

25
01:07.120 --> 01:11.510
playbooks. So as a result this gives us much greater granularity and

26
01:11.510 --> 01:13.360
specificity when retrieving

27
01:13.360 --> 01:16.750
information about the machines that we're managing in there for giving us

28
01:16.750 --> 01:18.240
greater control when we

29
01:18.240 --> 01:22.860
want to invoke conditional logic based on those particular custom facts. Okay

30
01:22.860 --> 01:23.920
so this sounds like

31
01:23.920 --> 01:28.580
a win the question is therefore how on earth do we even begin to define these

32
01:28.580 --> 01:29.600
custom facts because

33
01:29.600 --> 01:33.270
the answer is it's a little bit different of course because we're not going to
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

33
01:29.600 --> 01:33.270
the answer is it's a little bit different of course because we're not going to

34
01:33.270 --> 01:34.160
automatically

35
01:34.160 --> 01:37.360
gather them. Now the first thing to state is that with respect to Ansible we

36
01:37.360 --> 01:38.320
can actually have

37
01:38.320 --> 01:42.800
information stored about our devices in particular files say for example we

38
01:42.800 --> 01:44.240
want to define particular

39
01:44.240 --> 01:48.130
variables within our inventory directly albeit this is not really advised it's

40
01:48.130 --> 01:49.360
more of an antiquated

41
01:49.360 --> 01:53.890
approach but if you so wish you can do such a thing similarly you can define

42
01:53.890 --> 01:55.360
particular values

43
01:55.360 --> 01:59.330
you want to associate with particular groups in your group vars directory or

44
01:59.330 --> 02:00.640
particular values
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

44
01:59.330 --> 02:00.640
particular values

45
02:00.640 --> 02:06.350
relating to particular hosts in your host vars directory these are all options.

46
02:06.350 --> 02:06.880
Now the thing to

47
02:06.880 --> 02:10.940
note is it when we define this information in our inventory or say for example

48
02:10.940 --> 02:11.920
in our host vars

49
02:11.920 --> 02:16.070
directory where is this information actually stored well think about all of

50
02:16.070 --> 02:17.120
that information

51
02:17.120 --> 02:20.960
is going to be stored directly on the control node that is the device that is

52
02:20.960 --> 02:22.000
running Ansible in my

53
02:22.000 --> 02:26.570
case here this particular machine right here not the machines that I happen to

54
02:26.570 --> 02:27.360
be managing

55
02:27.360 --> 02:31.660
the difference in this case though is that when we go to define our own custom
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

55
02:27.360 --> 02:31.660
the difference in this case though is that when we go to define our own custom

56
02:31.660 --> 02:32.480
facts about a

57
02:32.480 --> 02:37.680
particular managed node those custom facts are actually going to be defined on

58
02:37.680 --> 02:38.640
the managed node

59
02:38.640 --> 02:42.480
themselves so once again we're going to have our Ansible control node right

60
02:42.480 --> 02:43.760
here as well as our

61
02:43.760 --> 02:48.560
blue box and our yellow box now like I say automatically Ansible is going to

62
02:48.560 --> 02:50.160
gather facts about these

63
02:50.160 --> 02:53.870
particular devices that we happen to be managing and these are going to be the

64
02:53.870 --> 02:55.360
automatically specified

65
02:55.360 --> 02:59.560
facts such as the architecture that IP addresses that type of thing and these

66
02:59.560 --> 03:00.560
custom facts are
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

66
02:59.560 --> 03:00.560
custom facts are

67
03:00.560 --> 03:04.980
going to be defined on the blue box as well as on the yellow box respectively

68
03:04.980 --> 03:06.400
now the question is

69
03:06.400 --> 03:10.590
if this information is going to be found remotely on these devices then how

70
03:10.590 --> 03:12.000
does Ansible know which

71
03:12.000 --> 03:15.900
information on that device is actually supposed to be a fact when we attempt to

72
03:15.900 --> 03:17.360
gather that information

73
03:17.360 --> 03:21.280
well the reality is we're going to have to follow a very specific convention on

74
03:21.280 --> 03:21.840
these managed

75
03:21.840 --> 03:26.320
devices we're going to define a very particular directory structure and the

76
03:26.320 --> 03:27.440
files within that

77
03:27.440 --> 03:31.460
directory structure are going to follow a particular format Ansible is going to
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

77
03:27.440 --> 03:31.460
directory structure are going to follow a particular format Ansible is going to

78
03:31.460 --> 03:32.640
look for this directory

79
03:32.640 --> 03:36.820
by default and it's going to seek to parse out the information defined within

80
03:36.820 --> 03:37.760
this directory

81
03:37.760 --> 03:42.720
so long as it follows that particular format so the question would be therefore

82
03:42.720 --> 03:43.440
what exactly is

83
03:43.440 --> 03:47.250
this format now the best place drumroll you guessed it to go as the Ansible

84
03:47.250 --> 03:48.960
documentation once again

85
03:48.960 --> 03:53.260
so once again if we search for Ansible facts let's click on the same link let's

86
03:53.260 --> 03:54.480
just scroll on down

87
03:54.480 --> 03:59.330
now if we go to the options notice we have this part right here adding custom

88
03:59.330 --> 04:00.800
facts let's click on this
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

88
03:59.330 --> 04:00.800
facts let's click on this

89
04:00.800 --> 04:04.510
now it says here as the Ansible is going to automatically gather a standard set

90
04:04.510 --> 04:05.360
of facts

91
04:05.360 --> 04:10.290
when we want to add these values we can do a few things we can write a custom

92
04:10.290 --> 04:11.280
facts module

93
04:11.280 --> 04:16.490
we can set temporary facts using the Ansible built-in set fact module but in

94
04:16.490 --> 04:17.680
this case here

95
04:17.680 --> 04:21.680
we're going to define permanent custom facts and we're going to do that using

96
04:21.680 --> 04:23.040
the facts dot

97
04:23.040 --> 04:27.550
d directory so as we can see here as per the documentation we have this

98
04:27.550 --> 04:28.640
particular folder

99
04:28.640 --> 04:32.620
right here we have the Etsy directory and inside of that we're going to have
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

99
04:28.640 --> 04:32.620
right here we have the Etsy directory and inside of that we're going to have

100
04:32.620 --> 04:33.920
the Ansible folder

101
04:33.920 --> 04:38.980
and inside of that yet again we're going to have this folder facts dot d now of

102
04:38.980 --> 04:39.680
course if you happen

103
04:39.680 --> 04:44.650
to be setting the rhce examination you should be very aware of this convention

104
04:44.650 --> 04:45.840
of using dot d

105
04:45.840 --> 04:49.870
within a directory it's super common in Linux and that is what we have to use

106
04:49.870 --> 04:50.960
right here now like

107
04:50.960 --> 04:56.060
you say this directory is going to be created on the remote host i.e the actual

108
04:56.060 --> 04:57.440
managed devices now

109
04:57.440 --> 05:01.610
one thing to state here is that this is the default location we do have an
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

109
04:57.440 --> 05:01.610
one thing to state here is that this is the default location we do have an

110
05:01.610 --> 05:02.800
option to specify

111
05:02.800 --> 05:07.360
a different directory if we so wish if we do so we're going to have to use the

112
05:07.360 --> 05:08.800
fact underscore path

113
05:08.800 --> 05:13.610
keyword to define a different path me personally i don't see any advantage of

114
05:13.610 --> 05:14.800
doing that so in my

115
05:14.800 --> 05:19.180
case here i'm just going to create this particular directory structure on all

116
05:19.180 --> 05:20.480
of my managed devices

117
05:20.480 --> 05:26.130
now inside of that directory structure this is where we specify custom facts

118
05:26.130 --> 05:26.880
now the files that

119
05:26.880 --> 05:31.380
we create have to end in the extension dot fact this is what Ansible is going
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

119
05:26.880 --> 05:31.380
we create have to end in the extension dot fact this is what Ansible is going

120
05:31.380 --> 05:32.160
to look for

121
05:32.160 --> 05:36.800
so files ending in dot fact within this particular directory is what we need on

122
05:36.800 --> 05:37.440
each of our managed

123
05:37.440 --> 05:43.610
devices now the actual file itself can be written in JSON format or if we so

124
05:43.610 --> 05:45.120
wish the i and i format

125
05:45.120 --> 05:49.110
so the i and i format is the format that we happen to be using with our Ansible

126
05:49.110 --> 05:49.760
inventory

127
05:49.760 --> 05:53.300
and at least in my opinion it's a little bit easier to create so that is going

128
05:53.300 --> 05:54.480
to be the format

129
05:54.480 --> 05:58.780
that i'm going to use now one thing to note here as well in the documentation

130
05:58.780 --> 06:00.160
we actually see this
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

130
05:58.780 --> 06:00.160
we actually see this

131
06:00.160 --> 06:05.600
other special variables called Ansible_Local this is effectively how we're

132
06:05.600 --> 06:06.400
going to be able to

133
06:06.400 --> 06:10.950
easily reference and parse out our locally generated custom facts about a

134
06:10.950 --> 06:12.160
device remember we had

135
06:12.160 --> 06:16.600
our Ansible_Fax magic variable which allowed us to gather the standard facts in

136
06:16.600 --> 06:17.440
this case here

137
06:17.440 --> 06:22.270
the custom facts can be gathered using Ansible_Local once again this is an Ans

138
06:22.270 --> 06:24.320
ible convention now just

139
06:24.320 --> 06:28.280
to keep things really quite straightforward the very first time i create this i

140
06:28.280 --> 06:29.280
'm going to just do

141
06:29.280 --> 06:33.040
all manually without the use of Ansible so let me go to one of my managed
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

141
06:29.280 --> 06:33.040
all manually without the use of Ansible so let me go to one of my managed

142
06:33.040 --> 06:34.080
devices so let's say

143
06:34.080 --> 06:38.270
for example if i log into the blue box right here now what did i say i had to

144
06:38.270 --> 06:39.280
create i'm going to

145
06:39.280 --> 06:43.750
have to create this directory structure so inside of my exit directory if i do

146
06:43.750 --> 06:44.880
an ls and i grip for

147
06:44.880 --> 06:48.230
the word Ansible we do not have an Ansible directory so what i will do is i

148
06:48.230 --> 06:50.000
will say sudo nk door

149
06:50.000 --> 06:55.020
Ansible_OK now i'll type in my super user password and if i do an ls and grip

150
06:55.020 --> 06:55.920
for Ansible

151
06:55.920 --> 07:01.340
now that directory does exist now within that directory if i cdm once again i'm
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

151
06:55.920 --> 07:01.340
now that directory does exist now within that directory if i cdm once again i'm

152
07:01.340 --> 07:02.400
going to have to create

153
07:02.400 --> 07:07.780
a directory called facts.d so we just do the same type of thing we do sudo nk

154
07:07.780 --> 07:10.160
door facts.d if i do an

155
07:10.160 --> 07:15.000
ls now we have that directory structure so if i go into this directory and i do

156
07:15.000 --> 07:16.080
a pwd this is the

157
07:16.080 --> 07:21.630
path i had to create etsay Ansible_Fax.d and within this directory i'm going to

158
07:21.630 --> 07:23.040
have to create files

159
07:23.040 --> 07:27.920
with the dot fact extension so let's just create a random fact about this okay

160
07:27.920 --> 07:28.400
so if i create a

161
07:28.400 --> 07:32.980
file called location and again it's got to end in dot fact and of course what i
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

161
07:28.400 --> 07:32.980
file called location and again it's got to end in dot fact and of course what i

162
07:32.980 --> 07:34.000
'm going to have to

163
07:34.000 --> 07:38.150
do is use super user privileges so i'll try that again with sudo now i have my

164
07:38.150 --> 07:39.600
custom fact file so

165
07:39.600 --> 07:43.720
if i go into this particular file using sudo vim what i'm going to do is either

166
07:43.720 --> 07:44.880
specify this within

167
07:44.880 --> 07:49.610
json or in my case here using i and i format so i'm going to give this a

168
07:49.610 --> 07:51.280
particular label and i

169
07:51.280 --> 07:55.600
will do this via my square brackets now i can actually define anything i so

170
07:55.600 --> 07:56.960
wish right here so let's

171
07:56.960 --> 08:00.620
just call this oh i don't know let's just say region underscore info again the
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

171
07:56.960 --> 08:00.620
just call this oh i don't know let's just say region underscore info again the

172
08:00.620 --> 08:01.600
name itself doesn't

173
08:01.600 --> 08:05.830
actually matter this is just going to be the information that we return back so

174
08:05.830 --> 08:07.200
within my region info i'm

175
08:07.200 --> 08:11.470
going to set some information and i'll just say the country is equal to the

176
08:11.470 --> 08:12.960
value Scotland and the

177
08:12.960 --> 08:17.580
language is going to be English and the city i will specify is Glasgow which is

178
08:17.580 --> 08:18.640
in Scotland where

179
08:18.640 --> 08:22.720
i am which is why i've got this really funny accent and let's just have some

180
08:22.720 --> 08:23.680
contact information

181
08:23.680 --> 08:27.870
just say contact john mcgovern ok so all we've done is create some custom fact

182
08:27.870 --> 08:29.040
information about

183
08:29.040 --> 08:33.130
our blue box device pretty much we're just imagining that the blue box happens
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

183
08:29.040 --> 08:33.130
our blue box device pretty much we're just imagining that the blue box happens

184
08:33.130 --> 08:34.800
to be located in Glasgow

185
08:34.800 --> 08:39.000
in Scotland and the manager of that device the one who's actually administering

186
08:39.000 --> 08:40.160
it is john mcgovern

187
08:40.160 --> 08:44.310
and in light of this information we would like this information to be gathered

188
08:44.310 --> 08:45.440
when we pull facts

189
08:45.440 --> 08:49.340
about this particular machine like i say this is not going to be the standard

190
08:49.340 --> 08:50.240
facts we gather

191
08:50.240 --> 08:55.280
this is purely custom defined so let's just write and quit here so now we have

192
08:55.280 --> 08:56.320
this location dot

193
08:56.320 --> 09:00.340
fact file and we now have the content within like i say within this particular
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

193
08:56.320 --> 09:00.340
fact file and we now have the content within like i say within this particular

194
09:00.340 --> 09:01.920
directory structure

195
09:01.920 --> 09:06.560
now if i happen to specify an answerable playbook to gather my answerable local

196
09:06.560 --> 09:07.520
facts we should

197
09:07.520 --> 09:11.970
actually pull this information about this particular device so let's go and do

198
09:11.970 --> 09:13.040
that so we go back to

199
09:13.040 --> 09:17.280
the control node let's create a new playbook called play three dot yml let's go

200
09:17.280 --> 09:18.160
into insert mode half

201
09:18.160 --> 09:21.150
of our three hyphens at the top we'll give this playbook a name and we'll just

202
09:21.150 --> 09:22.400
say playbook three

203
09:22.400 --> 09:27.900
pulling custom facts now as it transpires i will target the all group but

204
09:27.900 --> 09:29.200
remember we have only

205
09:29.200 --> 09:33.320
defined custom facts on one of our machines that is the blue box the yellow box
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

205
09:29.200 --> 09:33.320
defined custom facts on one of our machines that is the blue box the yellow box

206
09:33.320 --> 09:34.160
doesn't actually

207
09:34.160 --> 09:39.030
have any custom facts to find quite just yet so let's define our tasks and the

208
09:39.030 --> 09:39.920
task name just

209
09:39.920 --> 09:44.570
say print custom facts okay now we're going to use the debug module and the

210
09:44.570 --> 09:46.240
message is going to be

211
09:46.240 --> 09:50.320
within quotation marks and our double curly braces we're not going to say

212
09:50.320 --> 09:52.000
answerable facts this time

213
09:52.000 --> 09:56.240
this time we are going to say answerable underscore local to get those custom

214
09:56.240 --> 09:57.360
facts now one thing to

215
09:57.360 --> 10:01.700
state here just to be clear because we saw this in the previous video notice
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

215
09:57.360 --> 10:01.700
state here just to be clear because we saw this in the previous video notice

216
10:01.700 --> 10:02.960
when i use the message

217
10:02.960 --> 10:07.210
parameter i have to use my double curly braces and my quotation marks otherwise

218
10:07.210 --> 10:08.320
we would just print

219
10:08.320 --> 10:12.440
out the word answerable underscore local if you would prefer what you can

220
10:12.440 --> 10:13.600
actually do is you can

221
10:13.600 --> 10:16.970
just delete this here and you can specify that you want to use the var

222
10:16.970 --> 10:18.400
parameter and it's going to

223
10:18.400 --> 10:21.900
automatically interpret this value as a variable so you what you could do is

224
10:21.900 --> 10:22.800
just say answerable

225
10:22.800 --> 10:27.870
underscore facts or in this case here answerable underscore local that is just

226
10:27.870 --> 10:29.200
fine as it is also

227
10:29.200 --> 10:32.840
me myself i like to use the message parameter because quite often i actually
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

227
10:29.200 --> 10:32.840
me myself i like to use the message parameter because quite often i actually

228
10:32.840 --> 10:33.760
like to print a

229
10:33.760 --> 10:37.260
message in conjunction with the variable substitution but like i say either

230
10:37.260 --> 10:38.160
which way it's going to

231
10:38.160 --> 10:41.840
be fine just be aware that if you use the message parameter we do have to have

232
10:41.840 --> 10:42.800
the curly braces so

233
10:42.800 --> 10:46.620
like i say i'm going to use the answerable underscore local variable this time

234
10:46.620 --> 10:47.600
and let's see what we

235
10:47.600 --> 10:52.220
get then so let's write and quits and that will say answerable playbook play

236
10:52.220 --> 10:53.280
three dot yml and to

237
10:53.280 --> 10:57.420
answer give it a moment to pull the information and bam we get the information

238
10:57.420 --> 10:58.320
so look at this

239
10:58.320 --> 11:03.130
if we scroll on up a little bit notice the yellow box has an empty value that
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

239
10:58.320 --> 11:03.130
if we scroll on up a little bit notice the yellow box has an empty value that

240
11:03.130 --> 11:04.000
is because we do not

241
11:04.000 --> 11:09.040
have any locally defined custom facts however the blue box actually does have

242
11:09.040 --> 11:09.920
these custom facts

243
11:09.920 --> 11:15.020
now what i want you to notice is the actual format here location where did this

244
11:15.020 --> 11:15.680
come from

245
11:15.680 --> 11:20.640
well that is because on the actual blue box device the file itself is called

246
11:20.640 --> 11:22.560
location dot fact if

247
11:22.560 --> 11:26.570
we happen to change the name of this file this key would also change similarly

248
11:26.570 --> 11:27.440
we actually see

249
11:27.440 --> 11:30.630
the region info but that was actually the header we used within the square
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

249
11:27.440 --> 11:30.630
the region info but that was actually the header we used within the square

250
11:30.630 --> 11:32.080
brackets within the i and i

251
11:32.080 --> 11:37.610
file the actual location dot fact file and then inside of here this is all the

252
11:37.610 --> 11:38.400
information we

253
11:38.400 --> 11:42.770
defined we had the city was equal to Glasgow the contact is equal to john mc

254
11:42.770 --> 11:43.920
govern the country

255
11:43.920 --> 11:47.550
is Scotland the language is english that type of thing if we happen to change

256
11:47.550 --> 11:49.200
any of this information

257
11:49.200 --> 11:52.780
it would be reflected in this output so let's go back to the blue box once

258
11:52.780 --> 11:53.760
again let's do an

259
11:53.760 --> 11:58.820
LS on location dot fact if i happen to change the file let's just do so do envy

260
11:58.820 --> 11:59.680
and move location

261
11:59.680 --> 12:03.840
dot facts and let's just call it pizza dot fact just for a bit of fun type in
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

261
11:59.680 --> 12:03.840
dot facts and let's just call it pizza dot fact just for a bit of fun type in

262
12:03.840 --> 12:04.880
the password now

263
12:04.880 --> 12:08.710
we've got a pizza dot fact file once again though inside of the pizza dot fact

264
12:08.710 --> 12:09.760
file we have the same

265
12:09.760 --> 12:14.620
content if we gather our custom fact information if i rerun the playbook watch

266
12:14.620 --> 12:16.000
what actually happens

267
12:16.000 --> 12:19.560
we're not going to see a location here because that is not the name of the file

268
12:19.560 --> 12:20.480
instead let's run

269
12:20.480 --> 12:24.390
it again look at this right here check that output nobody see the information

270
12:24.390 --> 12:26.000
is in case within the

271
12:26.000 --> 12:29.960
pizza key and inside of that we have region info set a contact country language

272
12:29.960 --> 12:30.880
that type of thing
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

272
12:29.960 --> 12:30.880
that type of thing

273
12:30.880 --> 12:35.760
and again if we change the header here let's go into blue box and we do pseudo

274
12:35.760 --> 12:37.120
vim on pizza dot

275
12:37.120 --> 12:41.950
fact if i change region info again to anything we sawish let's just call this

276
12:41.950 --> 12:43.440
region info stuff

277
12:43.440 --> 12:48.100
if i write and quit rerun the playbook once again now we can see the output has

278
12:48.100 --> 12:48.880
changed once again

279
12:48.880 --> 12:52.910
now the relevance of this is this is how we're going to access particular

280
12:52.910 --> 12:54.240
information so we can

281
12:54.240 --> 12:58.360
see here we have the outer key which is called pizza let's go into our playbook

282
12:58.360 --> 12:59.040
once again

283
12:59.040 --> 13:04.350
and if i just use my dot notation and i just say print out answerable local dot
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

283
12:59.040 --> 13:04.350
and if i just use my dot notation and i just say print out answerable local dot

284
13:04.350 --> 13:05.280
pizza check what's

285
13:05.280 --> 13:09.180
going to happen rerun the playbook now notice the actual yellow box has failed

286
13:09.180 --> 13:10.160
because we do not

287
13:10.160 --> 13:14.130
have an attribute pizza no surprise is there because the yellow box does not

288
13:14.130 --> 13:15.040
have any values

289
13:15.040 --> 13:18.830
but look at the blue box we've actually peeled away the outer layer giving us

290
13:18.830 --> 13:20.160
access to the next key

291
13:20.160 --> 13:24.970
within the data which is region info stuff so let's go back in again and i can

292
13:24.970 --> 13:25.440
just keep

293
13:25.440 --> 13:30.420
passing this information so i'll say dot region underscore info underscore
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

293
13:25.440 --> 13:30.420
passing this information so i'll say dot region underscore info underscore

294
13:30.420 --> 13:32.240
stuff and rerun it again

295
13:32.240 --> 13:35.840
and now we have access to these particular keys so let's maybe say i wanted to

296
13:35.840 --> 13:36.800
find out who the

297
13:36.800 --> 13:41.140
actual contact was i could grab the contact key now so we're going to insert

298
13:41.140 --> 13:42.240
mode and i'll just say

299
13:42.240 --> 13:46.380
dot contacts rerun the playbook and check this out right here we actually see

300
13:46.380 --> 13:47.600
the information for

301
13:47.600 --> 13:52.400
blue box is john mcgoverned that is the contact whereas the yellow box we still

302
13:52.400 --> 13:53.600
have that failure

303
13:53.600 --> 13:58.080
now we can actually bypass this failure by invoking some conditional logic once

304
13:58.080 --> 13:59.360
again so if i go back

305
13:59.360 --> 14:02.760
in what i could do is have my conditional statement meaning that we only
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

305
13:59.360 --> 14:02.760
in what i could do is have my conditional statement meaning that we only

306
14:02.760 --> 14:04.080
attempt to print out this

307
14:04.080 --> 14:08.560
information when this particular information is defined so what i could do is i

308
14:08.560 --> 14:09.520
could say when

309
14:09.520 --> 14:14.190
answerable underscore local dot pizza is defined so pretty much if we don't

310
14:14.190 --> 14:16.000
actually have this key

311
14:16.000 --> 14:20.720
we will not try to parse this information for that particular host only when

312
14:20.720 --> 14:21.680
that host has this

313
14:21.680 --> 14:25.510
particular key so let's try this again run the playbook and check this out

314
14:25.510 --> 14:26.480
right here we no

315
14:26.480 --> 14:30.770
longer have any failures when it came to printing the custom facts the yellow
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

315
14:26.480 --> 14:30.770
longer have any failures when it came to printing the custom facts the yellow

316
14:30.770 --> 14:32.320
box was actually skipped

317
14:32.320 --> 14:36.330
that is because we did not have the actual keys defined on that particular

318
14:36.330 --> 14:37.520
device whereas on the

319
14:37.520 --> 14:42.230
blue box we were able to successfully print that custom information the contact

320
14:42.230 --> 14:43.280
is john mcgoverned

321
14:43.280 --> 14:46.210
now of course if we didn't want to do this manually what we could do is we

322
14:46.210 --> 14:47.520
could create a new playbook

323
14:47.520 --> 14:50.720
so let's create one called play four dot yml we're going to insert more to have

324
14:50.720 --> 14:51.920
our three hyphens

325
14:51.920 --> 14:55.970
just as usual give it a name we'll target the hosts we'll be all so this will

326
14:55.970 --> 14:56.640
be on all of our

327
14:56.640 --> 15:01.520
devices and this time the task we'll just give this a name of creating
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

327
14:56.640 --> 15:01.520
devices and this time the task we'll just give this a name of creating

328
15:01.520 --> 15:04.080
directory for custom facts

329
15:04.080 --> 15:07.990
all i will do is use the answerable built-in file module which we've seen

330
15:07.990 --> 15:09.120
before and we happen to

331
15:09.120 --> 15:12.500
have a required parameter of the actual path we're going to specify and that's

332
15:12.500 --> 15:13.120
going to be

333
15:13.120 --> 15:16.830
xa answerable fact dot d remember that is the actual path that answerable is

334
15:16.830 --> 15:17.680
going to seek to

335
15:17.680 --> 15:22.420
find these facts and our specify the state is a directory and then next i will

336
15:22.420 --> 15:23.360
use the answerable

337
15:23.360 --> 15:27.510
built-in copy module and the source is going to be able to create a file called

338
15:27.510 --> 15:29.040
general dot fact

339
15:29.040 --> 15:32.470
and the destination where is it going to be copied to it's going to be copied
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

339
15:29.040 --> 15:32.470
and the destination where is it going to be copied to it's going to be copied

340
15:32.470 --> 15:33.040
into that

341
15:33.040 --> 15:37.660
particular destination of xa answerable fact dot d so i will just save this

342
15:37.660 --> 15:38.880
right here and on my

343
15:38.880 --> 15:43.060
control node i will just create a file called general info dot fact and let's

344
15:43.060 --> 15:43.520
just have the

345
15:43.520 --> 15:48.170
heading bcbt nuggets and all i'm doing is creating some local facts that i want

346
15:48.170 --> 15:49.200
to be present on all

347
15:49.200 --> 15:54.270
my machines to just write some general information we'll just see the course is

348
15:54.270 --> 15:55.120
rhce we'll just say

349
15:55.120 --> 15:59.740
operating system is equal to rail okay doesn't actually matter here all we'll

350
15:59.740 --> 16:00.640
do is copy this
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

350
15:59.740 --> 16:00.640
do is copy this

351
16:00.640 --> 16:05.120
particular custom fact file onto both of the remote machines that means that

352
16:05.120 --> 16:05.840
both of those

353
16:05.840 --> 16:11.110
machines are going to have a custom fact known as general info and inside of

354
16:11.110 --> 16:12.080
that they're also going

355
16:12.080 --> 16:17.010
to have this particular information cbt nuggets with the course rhce and the

356
16:17.010 --> 16:18.720
operating system as

357
16:18.720 --> 16:24.000
rail so if i just say answerable playbook and do play for dot yml and to enter

358
16:24.000 --> 16:25.280
oh we have a syntax

359
16:25.280 --> 16:28.110
error let me just briefly fix that because we have a new task what i'm going to

360
16:28.110 --> 16:28.880
have to do here

361
16:28.880 --> 16:33.420
is to specify a name and i'll just say copy facts to remote machines okay so
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

361
16:28.880 --> 16:33.420
is to specify a name and i'll just say copy facts to remote machines okay so

362
16:33.420 --> 16:35.040
let's try this run

363
16:35.040 --> 16:38.880
again and as we can see from the summary the first task of creating the

364
16:38.880 --> 16:40.160
directory for custom

365
16:40.160 --> 16:44.460
facts was only applied on the yellow box that's because the blue box already

366
16:44.460 --> 16:45.440
had that particular

367
16:45.440 --> 16:50.430
directory but when it came to copying over our new custom facts both of those

368
16:50.430 --> 16:51.520
devices received

369
16:51.520 --> 16:55.990
that change so the cool thing is if i go back to our playbook three and this

370
16:55.990 --> 16:57.040
time if i just print

371
16:57.040 --> 17:01.410
out my answerable local right here and let's get rid of this conditional let's
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

371
16:57.040 --> 17:01.410
out my answerable local right here and let's get rid of this conditional let's

372
17:01.410 --> 17:02.480
save this and run

373
17:02.480 --> 17:06.400
the third playbook again let's see what custom facts we actually get back now

374
17:06.400 --> 17:10.800
ah-ha check this out let's scroll on up with the yellow box we actually see we

375
17:10.800 --> 17:11.360
have this

376
17:11.360 --> 17:15.420
information that we defined the general info which is the name of the failed

377
17:15.420 --> 17:17.040
general info dot fact

378
17:17.040 --> 17:21.000
and then we have our heading cbt nuggets and then the information contained

379
17:21.000 --> 17:21.440
within

380
17:21.440 --> 17:24.840
if we scroll on up to the blue box check this out right here the blue box

381
17:24.840 --> 17:25.840
actually has two

382
17:25.840 --> 17:29.840
options we have the general info which is all the information we just defined

383
17:29.840 --> 17:30.960
and we also have that
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

383
17:29.840 --> 17:30.960
and we also have that

384
17:30.960 --> 17:35.350
pizza information that we defined earlier so every single time we add a dot

385
17:35.350 --> 17:36.640
fact file within that

386
17:36.640 --> 17:41.330
particular directory structure on a device it's going to appear within our

387
17:41.330 --> 17:42.400
local facts right here

388
17:42.400 --> 17:46.690
and then whatever information we place within that particular file is going to

389
17:46.690 --> 17:48.720
be the nested data within
