WEBVTT

1
00:00.000 --> 00:05.220
Okay, so here's the deal. So so far we have been creating playbooks and inside

2
00:05.220 --> 00:05.400
of those

3
00:05.400 --> 00:09.720
playbooks we have been creating tasks in some cases multiple different tasks.

4
00:09.720 --> 00:10.200
Now the ability

5
00:10.200 --> 00:14.530
to create more than one task in a playbook is clearly quite essential. However,

6
00:14.530 --> 00:14.680
what

7
00:14.680 --> 00:18.760
actually doesn't mean to have multiple tasks within a single play? Well, when

8
00:18.760 --> 00:19.240
we have a

9
00:19.240 --> 00:24.390
single play, what we're essentially doing is targeting a particular group or a

10
00:24.390 --> 00:25.160
particular

11
00:25.160 --> 00:29.060
host in the network, or rather should I say in the inventory. Now as you know

12
00:29.060 --> 00:29.500
with an

13
00:29.500 --> 00:33.540
answer, but what you actually can do is you can invoke conditional logic so
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

13
00:29.500 --> 00:33.540
answer, but what you actually can do is you can invoke conditional logic so

14
00:33.540 --> 00:34.020
that some

15
00:34.020 --> 00:38.610
particular tasks are only performed on a subset of your target. But ultimately

16
00:38.610 --> 00:39.080
you are still

17
00:39.080 --> 00:44.470
working with that same target. What if you wanted to perform multiple different

18
00:44.470 --> 00:44.880
tasks

19
00:44.880 --> 00:49.600
against multiple groups or multiple different hosts? What you could do is you

20
00:49.600 --> 00:50.440
could create

21
00:50.440 --> 00:54.730
multiple different playbooks and then just run them one by one by one or

22
00:54.730 --> 00:55.960
alternatively,

23
00:55.960 --> 01:00.810
what you can also do is create a multi playbook. So let me show you how this
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

23
00:55.960 --> 01:00.810
what you can also do is create a multi playbook. So let me show you how this

24
01:00.810 --> 01:01.720
actually operates.

25
01:01.720 --> 01:05.430
It really is quite simple. So in the spirit of what we've already learned over

26
01:05.430 --> 01:05.680
on my

27
01:05.680 --> 01:09.860
blue box, let me create a test folder care. And if I go inside this folder, I

28
01:09.860 --> 01:10.440
'll just

29
01:10.440 --> 01:15.620
create a file called file one dot txt. I'll just say this is file one save you

30
01:15.620 --> 01:16.520
and similarly

31
01:16.520 --> 01:20.770
let it do the same for file to let's add a little smiley face in as well. Okay,

32
01:20.770 --> 01:20.880
just

33
01:20.880 --> 01:24.770
for a little bit of change. So let's write and quit. So inside this particular

34
01:24.770 --> 01:25.120
folder

35
01:25.120 --> 01:30.090
here, we have these two files, let's do the same thing over on the yellow box.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

35
01:25.120 --> 01:30.090
here, we have these two files, let's do the same thing over on the yellow box.

36
01:30.090 --> 01:30.560
So then

37
01:30.560 --> 01:34.140
this particular directory again, let's create a new folder just called test

38
01:34.140 --> 01:34.880
folder. And

39
01:34.880 --> 01:39.120
let's cd enter that directory and we'll create one called file one dot txt, and

40
01:39.120 --> 01:39.120
I'll

41
01:39.120 --> 01:43.820
just say file one blur and also create file to that txt and just say file to

42
01:43.820 --> 01:44.880
blah, blah,

43
01:44.880 --> 01:48.640
blah. Okay, let's save this. So let's go and create playbook four, let's go

44
01:48.640 --> 01:49.120
into insert

45
01:49.120 --> 01:52.780
mode, hover three hyphens at the top, and I'll give this a name. Now, what I'm

46
01:52.780 --> 01:53.040
going

47
01:53.040 --> 01:56.950
to say here is play number one. Okay, because it's going to be the first of

48
01:56.950 --> 01:57.640
many plays.

49
01:57.640 --> 02:02.150
And I'll just say archive files on all devices. So here's what I will do here.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

49
01:57.640 --> 02:02.150
And I'll just say archive files on all devices. So here's what I will do here.

50
02:02.150 --> 02:03.040
I'll specify

51
02:03.040 --> 02:06.580
my host, I want to target and I'll target the all group this time. Okay, again,

52
02:06.580 --> 02:06.920
I'll

53
02:06.920 --> 02:10.980
set gather facts to be false and now I'll define my tasks. So this time, I'll

54
02:10.980 --> 02:11.280
just say

55
02:11.280 --> 02:15.900
task one, or just say archive files. So I will use the community general

56
02:15.900 --> 02:16.920
archive module,

57
02:16.920 --> 02:20.420
I'll specify the path we're going to target, and it's going to be in the home n

58
02:20.420 --> 02:20.920
ugget user

59
02:20.920 --> 02:25.440
directory of both devices. And I'll take everything that ends in dot txt. And

60
02:25.440 --> 02:25.800
in fact,

61
02:25.800 --> 02:28.160
what it's going to be, it's going to be within the test folder as well,

62
02:28.160 --> 02:29.160
actually, isn't it?

63
02:29.160 --> 02:32.710
So everything that ends in dot txt within the test folder, then I'll specify
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

63
02:29.160 --> 02:32.710
So everything that ends in dot txt within the test folder, then I'll specify

64
02:32.710 --> 02:33.520
the destination

65
02:33.520 --> 02:36.530
that I want to copy this to, and let me just put in the temp directory. And I

66
02:36.530 --> 02:37.160
'll just call

67
02:37.160 --> 02:42.470
this my archive dot tar dot x z, and I specify the format is going to be x z

68
02:42.470 --> 02:43.840
compression.

69
02:43.840 --> 02:46.440
And in fact, let me just get rid of these quotation marks here. We don't want

70
02:46.440 --> 02:46.720
that to

71
02:46.720 --> 02:49.660
be literal. And let's just for the example here, let's create another task that

72
02:49.660 --> 02:50.080
is still

73
02:50.080 --> 02:54.480
within the same play. Okay, I'll just say task to print some message. So I'll

74
02:54.480 --> 02:54.800
just use

75
02:54.800 --> 02:58.910
the answerable built in debug module once again. And the message is going to be

76
02:58.910 --> 02:59.320
hello

77
02:59.320 --> 03:03.130
from, and I'll just use the inventory host name magic variable. The key point
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

77
02:59.320 --> 03:03.130
from, and I'll just use the inventory host name magic variable. The key point

78
03:03.130 --> 03:03.400
to note

79
03:03.400 --> 03:08.700
here is that both of these tasks are going to be executed against all hosts.

80
03:08.700 --> 03:09.360
However,

81
03:09.360 --> 03:12.700
let's now target a different group within my inventory. So what I now want to

82
03:12.700 --> 03:13.120
do here

83
03:13.120 --> 03:17.290
is not create a new task, ie, intended to send the task keyboard here. We want

84
03:17.290 --> 03:17.720
to create

85
03:17.720 --> 03:21.340
a new player entirely at the Martin's work. The very end here again, we have

86
03:21.340 --> 03:22.120
our hyphen,

87
03:22.120 --> 03:25.480
and now we give a name and now we just specify a new play. So I'll call this

88
03:25.480 --> 03:26.000
play play to

89
03:26.000 --> 03:29.810
it. And let's just say install engine X. Now the host I want to target you can

90
03:29.810 --> 03:30.200
target
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

90
03:29.810 --> 03:30.200
target

91
03:30.200 --> 03:34.120
anyone within the answerable inventory. So maybe I've got a group called engine

92
03:34.120 --> 03:34.520
X that

93
03:34.520 --> 03:37.170
is going to be a whole bunch of devices that are supposed to be configured with

94
03:37.170 --> 03:37.440
engine

95
03:37.440 --> 03:41.220
X. If you have that group within your inventory, then by all means you can

96
03:41.220 --> 03:42.160
target it. In my

97
03:42.160 --> 03:45.260
case here, I will just target the blue box this time. And now I just basically

98
03:45.260 --> 03:45.680
got about

99
03:45.680 --> 03:49.530
constructing another play again, or set gather facts to be false. And now I

100
03:49.530 --> 03:50.120
define all the

101
03:50.120 --> 03:54.280
tasks that I want to execute against this particular group. So let's give this

102
03:54.280 --> 03:54.720
a name.

103
03:54.720 --> 03:59.400
This will be task one of play number two. And I'll just say install engine X.

104
03:59.400 --> 03:59.720
So let's

105
03:59.720 --> 04:03.730
use the answerable built in DNF module, specify the name of the package we want
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

105
03:59.720 --> 04:03.730
use the answerable built in DNF module, specify the name of the package we want

106
04:03.730 --> 04:04.400
to install

107
04:04.400 --> 04:09.280
as engine X and the state is going to be present. Now I have another task, let

108
04:09.280 --> 04:10.240
's just say task

109
04:10.240 --> 04:13.880
two, and we'll just say start the engine X server. So this time I'll use the

110
04:13.880 --> 04:14.640
answerable

111
04:14.640 --> 04:18.110
built in service module, and I specify the name of the service I want to start

112
04:18.110 --> 04:18.600
is going

113
04:18.600 --> 04:22.780
to be engine X. And I'll say the state should be started. So all of these

114
04:22.780 --> 04:23.400
multiple tasks

115
04:23.400 --> 04:27.450
here are only going to be run against the blue box and not the yellow box. So

116
04:27.450 --> 04:27.800
let's

117
04:27.800 --> 04:30.930
maybe say for the yellow box, let's create a third play. And again, let's just
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

117
04:27.800 --> 04:30.930
maybe say for the yellow box, let's create a third play. And again, let's just

118
04:30.930 --> 04:31.640
for simplicity

119
04:31.640 --> 04:35.320
install something else, put something different. So we'll just say install HPD.

120
04:35.320 --> 04:35.960
Who are the

121
04:35.960 --> 04:39.700
hosts you want to target this time again, choose any subsection of your answer

122
04:39.700 --> 04:40.480
able inventory

123
04:40.480 --> 04:43.480
address or wish in my case here, I will just use the yellow box and just do

124
04:43.480 --> 04:44.200
something very,

125
04:44.200 --> 04:48.010
very similar, I'm going to gather facts, sit that to false. And now within my

126
04:48.010 --> 04:48.840
task here,

127
04:48.840 --> 04:53.880
again, I'll have task one of this new play, I'll just say install HPD, I'll use

128
04:53.880 --> 04:54.240
an answerable

129
04:54.240 --> 04:58.960
built in DNF module, the name of the program I'm going to install will be HPD.

130
04:58.960 --> 04:59.440
And the

131
04:59.440 --> 05:04.540
state should be present. And let's add another task on this third play. So task
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

131
04:59.440 --> 05:04.540
state should be present. And let's add another task on this third play. So task

132
05:04.540 --> 05:05.280
two, start

133
05:05.280 --> 05:09.390
the HPD server. So we use the answerable built in service module, this tender

134
05:09.390 --> 05:09.920
service

135
05:09.920 --> 05:14.740
to target will be HPD. And the state should be started. So effectively, we've

136
05:14.740 --> 05:15.040
kind of

137
05:15.040 --> 05:18.860
created three mini playbooks within a single playbook. So let's write and quits

138
05:18.860 --> 05:19.520
. If I say

139
05:19.520 --> 05:24.160
answerable playbook, play four dot YML answer, give it a moment. The playbook

140
05:24.160 --> 05:24.960
executes against

141
05:24.960 --> 05:29.830
both devices. Now we install engine X on only the blue box and begin starting

142
05:29.830 --> 05:30.720
that particular
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

142
05:29.830 --> 05:30.720
that particular

143
05:30.720 --> 05:36.010
server. Now the service is started. Now we begin the third play and install HPD

144
05:36.010 --> 05:37.120
, the first task

145
05:37.120 --> 05:41.000
of that third play. This time we're only targeting the yellow box notice. And

146
05:41.000 --> 05:42.000
now we begin to start

147
05:42.000 --> 05:46.110
that service to and now the playbook completes. So if we go and check the

148
05:46.110 --> 05:47.360
results now over on the

149
05:47.360 --> 05:50.890
yellow box within the temp directory, we should see here we have this new

150
05:50.890 --> 05:52.240
archive file. Now this

151
05:52.240 --> 05:55.750
should also be present on the blue box because that was also targeted for that

152
05:55.750 --> 05:56.720
particular play.

153
05:56.720 --> 06:00.060
So on the blue box, let's go into the temp directory to an LS as we can see
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

153
05:56.720 --> 06:00.060
So on the blue box, let's go into the temp directory to an LS as we can see

154
06:00.060 --> 06:00.480
here,

155
06:00.480 --> 06:04.320
we also have this archive file. Now with respect to the blue box, we should

156
06:04.320 --> 06:04.960
also have

157
06:04.960 --> 06:09.910
engine X installed to say system CTL status on engine X. And we can see here we

158
06:09.910 --> 06:10.880
do have engine

159
06:10.880 --> 06:15.100
X running. And just for posterity, if we try to check that for HPD on this

160
06:15.100 --> 06:16.720
particular device,

161
06:16.720 --> 06:20.080
that should not be present. And they can see here that particular unit service

162
06:20.080 --> 06:21.120
cannot be found.

163
06:21.120 --> 06:25.580
Similarly over on the yellow box, the inverse should be true. If I say system C

164
06:25.580 --> 06:28.000
TL status on HPD,

165
06:28.000 --> 06:31.680
that should now be running, which it is. However, if I try to check the status
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

165
06:28.000 --> 06:31.680
that should now be running, which it is. However, if I try to check the status

166
06:31.680 --> 06:32.800
on engine X, that

167
06:32.800 --> 06:36.330
should not be present, which we can see here, the engine X service unit could

168
06:36.330 --> 06:37.120
not be found.

169
06:37.120 --> 06:41.080
So as you can see with respect to playbooks, having multiple plays allows us to

170
06:41.080 --> 06:41.840
easily target

171
06:41.840 --> 06:46.000
different subsections of our inventory with a whole bunch of different tasks.
