WEBVTT

1
00:00.000 --> 00:04.710
So friends in the previous video, we learned how we could use the user module

2
00:04.710 --> 00:05.200
to create

3
00:05.200 --> 00:08.480
a simple user account on both of our managed devices.

4
00:08.480 --> 00:11.700
What we now want to do is to look at that group module so that we can

5
00:11.700 --> 00:12.660
subsequently create

6
00:12.660 --> 00:17.320
more groups on our devices and then we'll use the user account to actually add

7
00:17.320 --> 00:17.760
those

8
00:17.760 --> 00:19.960
users to those existing groups.

9
00:19.960 --> 00:22.760
So what we're waiting for, let's get to it.

10
00:22.760 --> 00:26.380
So all I will do is I'll create a new playbook, let's call this 1 play 2 and

11
00:26.380 --> 00:27.040
let's go in

12
00:27.040 --> 00:28.120
and edit it.

13
00:28.120 --> 00:31.520
So we have our three hyphens at the top and the name of this playbook is going
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

13
00:28.120 --> 00:31.520
So we have our three hyphens at the top and the name of this playbook is going

14
00:31.520 --> 00:31.960
to be play

15
00:31.960 --> 00:35.400
2 testing the group module.

16
00:35.400 --> 00:38.280
Once again, we're going to target the all group and this time I'm going to

17
00:38.280 --> 00:38.840
actually

18
00:38.840 --> 00:41.880
set gather facts to false to speed things up a little bit.

19
00:41.880 --> 00:46.030
So the first thing I will do is I'll specify my tasks right here and the first

20
00:46.030 --> 00:46.520
task is

21
00:46.520 --> 00:50.920
going to be, let's just say task 1 creating group 1.

22
00:50.920 --> 00:55.290
So we're going to use the Ansible built in group module and what do we have to

23
00:55.290 --> 00:55.840
supply

24
00:55.840 --> 00:59.090
here where we're going to have to supply the names that is a mandatory

25
00:59.090 --> 00:59.920
parameter and the

26
00:59.920 --> 01:02.720
name of the group in this case here is going to be group 1.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

26
00:59.920 --> 01:02.720
name of the group in this case here is going to be group 1.

27
01:02.720 --> 01:06.510
Now what I'm also going to do is I'm going to set the state to present meaning

28
01:06.510 --> 01:06.880
that I

29
01:06.880 --> 01:09.520
want this group to be on the device.

30
01:09.520 --> 01:14.190
So for now all I will do here is I'll just write and quit and let me go over to

31
01:14.190 --> 01:14.920
my managed

32
01:14.920 --> 01:16.200
devices for a moment.

33
01:16.200 --> 01:20.460
So if I cat the Etsy group file, notice we actually do not have a group 1 group

34
01:20.460 --> 01:21.000
account

35
01:21.000 --> 01:24.640
but when we run this playbook, things should be a little bit different.

36
01:24.640 --> 01:25.640
So that is exactly what we'll do.

37
01:25.640 --> 01:27.200
We'll say Ansible playbook.

38
01:27.200 --> 01:30.040
I will say play to that YML answer.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

38
01:27.200 --> 01:30.040
I will say play to that YML answer.

39
01:30.040 --> 01:33.380
And as we can see here, we have two changes, one in the blue box and another on

40
01:33.380 --> 01:34.000
the yellow

41
01:34.000 --> 01:35.000
box.

42
01:35.000 --> 01:36.000
That is a good sign.

43
01:36.000 --> 01:37.000
So let's go and check.

44
01:37.000 --> 01:38.000
So we'll go to the yellow box.

45
01:38.000 --> 01:40.520
Let's arrow up and we'll just cat the grips once again.

46
01:40.520 --> 01:42.320
Look at this down the very bottom.

47
01:42.320 --> 01:48.210
We have group 1 and we have automatically be assigned the group ID of 1 1 0 0

48
01:48.210 --> 01:48.400
and the

49
01:48.400 --> 01:52.860
same thing if we go over to the blue box, let's just cat Etsy group and to

50
01:52.860 --> 01:53.800
enter, look

51
01:53.800 --> 01:57.040
at the very bottom, we see group 1 there as well.

52
01:57.040 --> 01:58.200
So check this out right now.

53
01:58.200 --> 02:02.680
Let me go back to my yellow box right here and I'm going to say ID Fred.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

53
01:58.200 --> 02:02.680
Let me go back to my yellow box right here and I'm going to say ID Fred.

54
02:02.680 --> 02:06.280
Now what this actually shows us, it shows us Fred's group membership.

55
02:06.280 --> 02:09.710
We can see Fred is a member of the Fred group and that is the only one Fred is

56
02:09.710 --> 02:10.240
a member

57
02:10.240 --> 02:11.240
of.

58
02:11.240 --> 02:15.220
So what if I go into my playbook and I specify that Fred should be a member of

59
02:15.220 --> 02:15.960
group 1.

60
02:15.960 --> 02:16.960
Let's see what actually happens.

61
02:16.960 --> 02:19.520
So all I'll do is I'll create play 3 right now.

62
02:19.520 --> 02:23.480
Just do my basics, my 3 hyphens, get the player name and I'll target the all

63
02:23.480 --> 02:23.760
group.

64
02:23.760 --> 02:28.320
Let's just say gather facts as equal to false and now we define our tasks.

65
02:28.320 --> 02:31.480
The name here is going to be add Fred to group 1.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

65
02:28.320 --> 02:31.480
The name here is going to be add Fred to group 1.

66
02:31.480 --> 02:34.440
Now quick question, which module should I use here?

67
02:34.440 --> 02:38.520
Should it actually be the group module or will it be the user module?

68
02:38.520 --> 02:42.970
Well the answer is actually the user module because recall we use the user

69
02:42.970 --> 02:44.080
module to assign

70
02:44.080 --> 02:46.520
users to already existing groups.

71
02:46.520 --> 02:48.520
We use the group module to create those groups.

72
02:48.520 --> 02:52.920
Now the group 1 here has been created in the previous playbook.

73
02:52.920 --> 02:56.160
All we want to do is assign the user to that particular group.

74
02:56.160 --> 03:01.110
So I'll use the user module and I'll specify that the name is going to be Fred
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

74
02:56.160 --> 03:01.110
So I'll use the user module and I'll specify that the name is going to be Fred

75
03:01.110 --> 03:01.600
and all I'm

76
03:01.600 --> 03:04.960
going to do is I'm going to specify which groups Fred should be a member of.

77
03:04.960 --> 03:09.360
Now watch this if I just say group 1 right here and I leave this as it is.

78
03:09.360 --> 03:10.840
Watch what happens when I run this playbook.

79
03:10.840 --> 03:12.360
So let's run play 3.YML.

80
03:12.360 --> 03:13.360
I'll answer.

81
03:13.360 --> 03:15.080
We have a change on two devices.

82
03:15.080 --> 03:17.520
Let's go back to our yellow box then.

83
03:17.520 --> 03:20.640
So if I arrow up and to enter, look at this.

84
03:20.640 --> 03:22.640
Fred is actually a member of two groups now.

85
03:22.640 --> 03:25.560
He's a member of the Fred group and group 1 now.

86
03:25.560 --> 03:27.320
Isn't this a little bit strange?

87
03:27.320 --> 03:32.020
Then I say earlier on that we would have to use the append parameter to
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

87
03:27.320 --> 03:32.020
Then I say earlier on that we would have to use the append parameter to

88
03:32.020 --> 03:33.120
actually append

89
03:33.120 --> 03:34.880
Fred onto new groups.

90
03:34.880 --> 03:38.000
Otherwise the group would just override Fred's group membership.

91
03:38.000 --> 03:40.040
Well this is something I really want to highlight to you.

92
03:40.040 --> 03:43.200
This is only applicable to the secondary groups.

93
03:43.200 --> 03:48.330
This will in fact not override Fred's primary membership to his automatically

94
03:48.330 --> 03:49.280
created Fred

95
03:49.280 --> 03:50.280
group.

96
03:50.280 --> 03:51.840
So just be aware of that distinction.

97
03:51.840 --> 03:53.040
So check this out then.

98
03:53.040 --> 03:55.200
Let's go back and make a modification.

99
03:55.200 --> 03:59.280
What we will do is we'll go back into the second playbook right here and let's

100
03:59.280 --> 03:59.760
create

101
03:59.760 --> 04:00.760
another group here.
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

101
03:59.760 --> 04:00.760
another group here.

102
04:00.760 --> 04:01.760
So we'll say name.

103
04:01.760 --> 04:07.360
I'll just say task 2 creating group 2 and I'll say answerable built in group

104
04:07.360 --> 04:07.560
and the

105
04:07.560 --> 04:11.950
name this time is going to be group 2 and the state well that's going to be

106
04:11.950 --> 04:12.640
present.

107
04:12.640 --> 04:13.640
Perfect.

108
04:13.640 --> 04:18.000
So let's just write and quit and let's rerun playbook 2 and to enter.

109
04:18.000 --> 04:21.600
You can see we have a change on both of our devices if we go back to the yellow

110
04:21.600 --> 04:21.840
box to

111
04:21.840 --> 04:23.440
clear the screen and we'll cat.

112
04:23.440 --> 04:25.000
It's a group.

113
04:25.000 --> 04:30.140
Then the very bottom we can see here we have group number 2 and the same thing
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

113
04:25.000 --> 04:30.140
Then the very bottom we can see here we have group number 2 and the same thing

114
04:30.140 --> 04:30.720
will be

115
04:30.720 --> 04:32.640
true on the blue box.

116
04:32.640 --> 04:36.920
Now if we go back to our playbook 3 right here let's modify this.

117
04:36.920 --> 04:39.600
Let's just try to assign Fred membership to group number 2 now.

118
04:39.600 --> 04:40.600
Okay so check this out.

119
04:40.600 --> 04:44.020
Now just before I do this remember Fred's current membership is with the

120
04:44.020 --> 04:44.800
primary group

121
04:44.800 --> 04:46.640
Fred and group 1.

122
04:46.640 --> 04:50.630
When we push this playbook watch what happens if I enter now the task actually

123
04:50.630 --> 04:51.200
says here

124
04:51.200 --> 04:54.140
adding Fred to group 1 I really should have changed that but nevertheless the

125
04:54.140 --> 04:54.680
actual group

126
04:54.680 --> 04:56.680
has been created as group 2.

127
04:56.680 --> 04:57.880
This part here doesn't actually matter.

128
04:57.880 --> 05:01.820
If I go back here and I see ID Fred look at this look at Fred's group
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

128
04:57.880 --> 05:01.820
If I go back here and I see ID Fred look at this look at Fred's group

129
05:01.820 --> 05:02.960
membership Fred

130
05:02.960 --> 05:06.820
is still a member of the primary group Fred but Fred is not a member of only

131
05:06.820 --> 05:07.600
group 2 as

132
05:07.600 --> 05:11.540
a secondary group group one's membership has now been revoked and the same

133
05:11.540 --> 05:12.280
thing is going

134
05:12.280 --> 05:14.480
to be true on the blue box device.

135
05:14.480 --> 05:18.590
So just be aware when we are overriding group membership that doesn't actually

136
05:18.590 --> 05:19.120
apply to

137
05:19.120 --> 05:21.920
the primary group itself that's still going to stay there.

138
05:21.920 --> 05:23.720
Very very important detail to remember.

139
05:23.720 --> 05:28.260
So let's go back to our playbook right here and all I'll do is I will modify

140
05:28.260 --> 05:29.000
this to add

141
05:29.000 --> 05:35.210
Fred back to group 1 and this time I'm going to set the append value to true to
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

141
05:29.000 --> 05:35.210
Fred back to group 1 and this time I'm going to set the append value to true to

142
05:35.210 --> 05:36.200
check this

143
05:36.200 --> 05:40.750
out now okay let's write and quit let's run the playbook for play number 3 and

144
05:40.750 --> 05:41.280
to enter

145
05:41.280 --> 05:47.080
we see a change and if we go back now and let's arrow up here look at this.

146
05:47.080 --> 05:50.950
Whilst we only pushed a change for group number 1 due to the fact we've app

147
05:50.950 --> 05:51.680
ended Fred

148
05:51.680 --> 05:56.700
has now 2 secondary memberships to both group 1 and group 2 that is the effect

149
05:56.700 --> 05:57.120
that we're

150
05:57.120 --> 06:01.070
getting here and all I'll do is I'll copy over play number 2 and I'll create
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

150
05:57.120 --> 06:01.070
getting here and all I'll do is I'll copy over play number 2 and I'll create

151
06:01.070 --> 06:01.720
one called

152
06:01.720 --> 06:05.160
play 4.yml and let's go in here okay.

153
06:05.160 --> 06:09.880
So I'll create task number 3 I'm just creating group 3 I'll use Ansible built

154
06:09.880 --> 06:10.640
in group once

155
06:10.640 --> 06:14.800
again the name this time will be group 3 and the state is going to be present

156
06:14.800 --> 06:15.080
and let's

157
06:15.080 --> 06:18.830
just add another one for good measure that's going to be task 4 creating group

158
06:18.830 --> 06:19.360
4 we'll

159
06:19.360 --> 06:23.480
have Ansible built in group this one here is going to have the name of group 4

160
06:23.480 --> 06:23.800
and the

161
06:23.800 --> 06:25.640
state is going to be present.

162
06:25.640 --> 06:28.860
Now one thing I want to highlight to you here check this out okay if I go to

163
06:28.860 --> 06:29.480
the top right

164
06:29.480 --> 06:34.400
now and let's just create a new task here called name I'll just create new user
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

164
06:29.480 --> 06:34.400
now and let's just create a new task here called name I'll just create new user

165
06:34.400 --> 06:34.680
and

166
06:34.680 --> 06:38.850
I'll use the Ansible built in user module and we'll have a user called Michael

167
06:38.850 --> 06:39.280
we'll

168
06:39.280 --> 06:45.550
give Michael a shell of then bash to give a user ID of 1 1 2 2 now when it

169
06:45.550 --> 06:47.080
comes to groups

170
06:47.080 --> 06:50.730
now what we'll try to do here is we'll try to assign a group membership to a

171
06:50.730 --> 06:51.240
group that

172
06:51.240 --> 06:54.800
doesn't actually exist yet so we'll say group number 4 okay.

173
06:54.800 --> 06:58.490
So remember the play book is going to execute sequentially we will attempt to

174
06:58.490 --> 06:59.280
perform this

175
06:59.280 --> 07:03.200
particular task first and when they go to assign group 4 that will not be
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

175
06:59.280 --> 07:03.200
particular task first and when they go to assign group 4 that will not be

176
07:03.200 --> 07:03.840
created yet

177
07:03.840 --> 07:07.900
that will not get created until we get down to the bottom of the play book okay

178
07:07.900 --> 07:08.160
.

179
07:08.160 --> 07:13.000
So watch what happens here I will say Ansible play book play 4.yml and to enter

180
07:13.000 --> 07:13.320
look at this

181
07:13.320 --> 07:17.730
right here tells me that group 4 does not exist so we're actually getting a

182
07:17.730 --> 07:18.280
failure

183
07:18.280 --> 07:22.940
here now if I just modify this I'm going to play 4 and let me just copy this

184
07:22.940 --> 07:23.840
right here

185
07:23.840 --> 07:28.390
and all I will do is I'll move this particular task down to the bottom of the

186
07:28.390 --> 07:29.120
play so it's

187
07:29.120 --> 07:32.890
now going to execute after the creation of group 4 and all I will do is I'll
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

187
07:29.120 --> 07:32.890
now going to execute after the creation of group 4 and all I will do is I'll

188
07:32.890 --> 07:33.480
scroll up

189
07:33.480 --> 07:37.860
to the top and I'll just remove all this here so now the task is going to be

190
07:37.860 --> 07:38.800
creating all

191
07:38.800 --> 07:42.650
the groups ensuring they're on the actual device and then we can assign the

192
07:42.650 --> 07:43.360
membership

193
07:43.360 --> 07:48.120
okay so let's check this out we'll say Ansible play book play 4.yml and to

194
07:48.120 --> 07:49.200
enter now we seem

195
07:49.200 --> 07:53.530
to have a success and if we actually go back to our devices if I cat the Etsy

196
07:53.530 --> 07:54.280
group file

197
07:54.280 --> 07:57.900
we can indeed see that we have these additional groups right here and when it

198
07:57.900 --> 07:58.560
comes to the

199
07:58.560 --> 08:03.840
user Michael Michael is a member of group number 4 as per our direction now let
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

199
07:58.560 --> 08:03.840
user Michael Michael is a member of group number 4 as per our direction now let

200
08:03.840 --> 08:04.480
me just briefly

201
08:04.480 --> 08:08.170
change this right now and I'm going to play 4 once again and let's say I wanted

202
08:08.170 --> 08:08.480
to add

203
08:08.480 --> 08:12.660
Michael to multiple groups okay because like I say right here if I say ID

204
08:12.660 --> 08:13.760
Michael Michael

205
08:13.760 --> 08:18.840
only as a member of the primary group of Michael and one second group group 4

206
08:18.840 --> 08:19.200
now we know we

207
08:19.200 --> 08:22.560
can sequentially just keep adding on different groups but if you want to do in

208
08:22.560 --> 08:23.720
one fell swoop

209
08:23.720 --> 08:28.040
remember as per the documentation this particular parameter takes a list of

210
08:28.040 --> 08:29.000
strings so what I

211
08:29.000 --> 08:32.540
can do is I can say I want Michael to be a member of group 1 and then have a
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

211
08:29.000 --> 08:32.540
can do is I can say I want Michael to be a member of group 1 and then have a

212
08:32.540 --> 08:32.960
comma to

213
08:32.960 --> 08:37.850
specify a new value okay so then I can say group 2 as well as group 3 now I

214
08:37.850 --> 08:38.440
could just

215
08:38.440 --> 08:43.260
add these particular groups and right now what would happen this would override

216
08:43.260 --> 08:43.640
Michael's

217
08:43.640 --> 08:47.100
group 4 membership but I don't want to do that what I want to do is I want to

218
08:47.100 --> 08:47.500
say a

219
08:47.500 --> 08:52.720
pen is equal to true now I run the playbooks or just say answer my playbook

220
08:52.720 --> 08:54.220
play 4 dot yml

221
08:54.220 --> 08:58.160
and to enter check this out right here let's go back to our devices let's check

222
08:58.160 --> 08:58.720
the ID for

223
08:58.720 --> 09:02.670
Michael and look at this Michael here is now a member of the Michael primary
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

223
08:58.720 --> 09:02.670
Michael and look at this Michael here is now a member of the Michael primary

224
09:02.670 --> 09:03.740
group as expected

225
09:03.740 --> 09:07.100
but also a member of groups 1 2 3 and 4
