WEBVTT

1
00:00.000 --> 00:04.400
So friends, in this particular video, what I want to discuss with you is the

2
00:04.400 --> 00:06.320
user module within Ansible.

3
00:06.320 --> 00:11.840
Now you will recall having sat the RH CSA examination, we understand that on

4
00:11.840 --> 00:12.720
Linux systems,

5
00:12.720 --> 00:17.550
we have the ability to create users and then specify a whole list of associated

6
00:17.550 --> 00:18.400
attributes.

7
00:18.400 --> 00:22.000
Things like what type of shell environment should that user get? Should they

8
00:22.000 --> 00:22.720
get a

9
00:22.720 --> 00:27.140
born shell? Should they get a bad shell? That type of thing? Should they be

10
00:27.140 --> 00:28.000
granted some type

11
00:28.000 --> 00:32.250
of home directory upon the creation of their account? And we also have other
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

11
00:28.000 --> 00:32.250
of home directory upon the creation of their account? And we also have other

12
00:32.250 --> 00:32.960
considerations

13
00:32.960 --> 00:36.850
to recall when we happen to create a user account, say for example, the user is

14
00:36.850 --> 00:38.000
called John,

15
00:38.000 --> 00:42.410
then by default they're going to be associated with a primary group known as

16
00:42.410 --> 00:43.280
John, pretty much

17
00:43.280 --> 00:47.910
the same as their actual username, but we also have the ability to invoke

18
00:47.910 --> 00:49.360
secondary groups.

19
00:49.360 --> 00:52.900
So that means that the user doesn't have to just be a member of one single

20
00:52.900 --> 00:53.360
group,

21
00:53.360 --> 00:57.280
we can be a member of multiple groups. So in this particular video, we're going

22
00:57.280 --> 00:57.520
to

23
00:57.520 --> 01:02.310
address some of the issues and concerns around creating these particular users
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

23
00:57.520 --> 01:02.310
address some of the issues and concerns around creating these particular users

24
01:02.310 --> 01:03.120
with these

25
01:03.120 --> 01:08.400
specified attributes. So one thing to actually say on that note about the

26
01:08.400 --> 01:12.480
assignment of groups to a particular user is that when it comes to the actual

27
01:12.480 --> 01:13.200
creation

28
01:13.200 --> 01:18.060
of our user accounts, this actually can be handled via the user module in Ans

29
01:18.060 --> 01:18.640
ible.

30
01:18.640 --> 01:23.360
I mean, there is no real surprise there is the user module after all. However,

31
01:23.360 --> 01:23.920
when it comes to

32
01:23.920 --> 01:28.240
the creation of groups with an Ansible, we actually have a dedicated group

33
01:28.240 --> 01:29.600
module to handle that

34
01:29.600 --> 01:33.420
particular task. Now this might seem obvious, but it is worth pointing out for
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

34
01:29.600 --> 01:33.420
particular task. Now this might seem obvious, but it is worth pointing out for

35
01:33.420 --> 01:34.240
clarification,

36
01:34.240 --> 01:38.960
when we want to create a particular user using the user module, then we can

37
01:38.960 --> 01:39.920
assign the values

38
01:39.920 --> 01:44.360
such as the username, as well as the shell they're going to have. However, if

39
01:44.360 --> 01:45.680
we are going to specify

40
01:45.680 --> 01:49.950
which groups they belong to, well, those groups actually have to exist for the

41
01:49.950 --> 01:51.120
user module to operate

42
01:51.120 --> 01:55.320
correctly. Pretty much what I'm suggesting is that you actually use the group

43
01:55.320 --> 01:57.120
module first to create

44
01:57.120 --> 02:00.740
all the necessary groups such as you know, group one, group two, group three,
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

44
01:57.120 --> 02:00.740
all the necessary groups such as you know, group one, group two, group three,

45
02:00.740 --> 02:01.920
that type of thing.

46
02:01.920 --> 02:06.800
And once those groups actually exist, then use the user module to specify the

47
02:06.800 --> 02:07.840
user, say for example,

48
02:07.840 --> 02:12.400
John, and then with this particular module, you can assign the user John

49
02:12.400 --> 02:13.600
membership into these

50
02:13.600 --> 02:16.720
existing groups. So that really is the workflow that we're going to see when we

51
02:16.720 --> 02:17.680
happen to invoke

52
02:17.680 --> 02:21.030
the creation of particular groups. So the very first thing that we're going to

53
02:21.030 --> 02:21.920
do is of course,

54
02:21.920 --> 02:25.290
go to the documentation. And from that point on, we'll be able to figure out

55
02:25.290 --> 02:26.480
how to actually use

56
02:26.480 --> 02:30.280
this particular module or these two particular modules, should I say. Okay, so
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

56
02:26.480 --> 02:30.280
this particular module or these two particular modules, should I say. Okay, so

57
02:30.280 --> 02:31.120
let's get going.

58
02:31.120 --> 02:35.730
So recall, we can actually view the documentation directly via the command line

59
02:35.730 --> 02:36.880
interface. This

60
02:36.880 --> 02:40.780
would be the Ansible document. And I can do dash L for a listing. Now, if we

61
02:40.780 --> 02:41.840
happen to scroll on

62
02:41.840 --> 02:46.320
down, notice we have our built in group module, which is going to allow us to

63
02:46.320 --> 02:48.000
add or remove groups

64
02:48.000 --> 02:52.280
and scrolling on down a little bit further, we have this user module to manage

65
02:52.280 --> 02:52.880
user accounts.

66
02:52.880 --> 02:56.960
Now, if you do prefer, by all means, you can use this command line utility. It

67
02:56.960 --> 02:57.840
's very, very useful

68
02:57.840 --> 03:01.570
in the examination. But for the purposes of clarity, I just think it's a little
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

68
02:57.840 --> 03:01.570
in the examination. But for the purposes of clarity, I just think it's a little

69
03:01.570 --> 03:02.720
bit easier to consume

70
03:02.720 --> 03:06.460
on the web browser. So that is where I'm going to go just now. So if you just

71
03:06.460 --> 03:07.280
happened to search

72
03:07.280 --> 03:10.220
for Ansible, use our module, we can click this top link here in the

73
03:10.220 --> 03:11.680
documentation for Ansible.

74
03:11.680 --> 03:16.430
And let me just scroll on a little bit so we can see this module is a part of

75
03:16.430 --> 03:17.200
Ansible core,

76
03:17.200 --> 03:20.100
meaning that we don't have to install anything. No surprises there. It is a

77
03:20.100 --> 03:21.280
built in module after

78
03:21.280 --> 03:24.850
all. And if we scroll on down, we can see here, this is going to allow us to

79
03:24.850 --> 03:26.000
manage user accounts

80
03:26.000 --> 03:30.350
and user attributes. Notice though, if we happen to be also managing Windows
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

80
03:26.000 --> 03:30.350
and user attributes. Notice though, if we happen to be also managing Windows

81
03:30.350 --> 03:31.120
system with then

82
03:31.120 --> 03:35.060
Earth topology, we actually have a separate module for that. We actually have

83
03:35.060 --> 03:36.000
the Ansible

84
03:36.000 --> 03:39.670
Windows module. And then the when users are so be aware, this is not going to

85
03:39.670 --> 03:40.720
work on Windows

86
03:40.720 --> 03:44.710
based systems. So let's look at the parameters here. Check this one out right

87
03:44.710 --> 03:45.600
here. This is actually

88
03:45.600 --> 03:49.450
an important one append. We have a billion value, meaning that we're going to

89
03:49.450 --> 03:50.960
supply either true

90
03:50.960 --> 03:55.310
or false. And notice what happens here, it says if we set the value to true, we

91
03:55.310 --> 03:56.240
're going to add

92
03:56.240 --> 04:01.520
the user to the groups specified in the groups. Basically, this here is a non
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

92
03:56.240 --> 04:01.520
the user to the groups specified in the groups. Basically, this here is a non

93
04:01.520 --> 04:02.240
parameter that we

94
04:02.240 --> 04:05.340
can supply. Let me just go and show you that just now. So let's just scroll on

95
04:05.340 --> 04:06.320
down a little bit

96
04:06.320 --> 04:10.270
further. Check this one right here. It says we have the groups option and

97
04:10.270 --> 04:11.760
information we supply is a

98
04:11.760 --> 04:15.960
list of strings. And this is how we supply a list of all the supplementary

99
04:15.960 --> 04:17.440
groups, which the user is

100
04:17.440 --> 04:21.550
also a member of. So remember, we just talked about this, a user can be a

101
04:21.550 --> 04:23.360
member of multiple groups.

102
04:23.360 --> 04:27.890
But look at the default behavior. By default, the user is going to be removed

103
04:27.890 --> 04:29.280
from all other

104
04:29.280 --> 04:34.940
groups. So think about any groups you do not specify within this option, the
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

104
04:29.280 --> 04:34.940
groups. So think about any groups you do not specify within this option, the

105
04:34.940 --> 04:35.840
user is going to be

106
04:35.840 --> 04:39.560
removed from those groups by their omission. Now we can actually override this

107
04:39.560 --> 04:40.720
behavior by looking

108
04:40.720 --> 04:45.290
at the parameter we just saw before append when we set the append value to true

109
04:45.290 --> 04:46.240
. It means that the

110
04:46.240 --> 04:50.170
user is going to keep the membership to all other existing groups, even the

111
04:50.170 --> 04:51.600
ones we don't mention.

112
04:51.600 --> 04:56.540
And any groups we supplies, such as let's say we supply group four, group five,

113
04:56.540 --> 04:57.680
and group six.

114
04:57.680 --> 05:01.620
If the user is already a member of group one, two, and three, by setting the
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

114
04:57.680 --> 05:01.620
If the user is already a member of group one, two, and three, by setting the

115
05:01.620 --> 05:02.880
value to append,

116
05:02.880 --> 05:07.440
the user will be a member of group four, five, and six, as well as retaining

117
05:07.440 --> 05:07.920
their initial

118
05:07.920 --> 05:12.280
membership to groups of one, two, and three, whereas if we do not specify that

119
05:12.280 --> 05:13.360
we should append to

120
05:13.360 --> 05:17.190
these values, we would effectively remove their membership from groups one, two

121
05:17.190 --> 05:17.920
, and three,

122
05:17.920 --> 05:21.100
and they would only be a member of groups four, five, and six. That is what we

123
05:21.100 --> 05:21.760
're talking about

124
05:21.760 --> 05:25.660
here. As I mentioned earlier, we have the option to specify a user's home

125
05:25.660 --> 05:27.200
directory upon creation.

126
05:27.200 --> 05:31.680
We can do so by specifying the path and the home parameter. Now this particular
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

126
05:27.200 --> 05:31.680
We can do so by specifying the path and the home parameter. Now this particular

127
05:31.680 --> 05:32.640
parameter is

128
05:32.640 --> 05:36.240
very, very important. We can tell because it is a require parameter, meaning

129
05:36.240 --> 05:36.960
that the module will

130
05:36.960 --> 05:41.110
not operate without this option supplied. And that is the name pretty much we

131
05:41.110 --> 05:42.560
just have to specify

132
05:42.560 --> 05:47.200
or provide the name of the user that we want the user module to either create,

133
05:47.200 --> 05:48.640
remove, or modify.

134
05:48.640 --> 05:53.260
So this is non-negotiable. And if we just get down a little bit further, we can

135
05:53.260 --> 05:54.320
also supply a

136
05:54.320 --> 05:57.670
password for that particular user. We'll talk about that a little bit later on

137
05:57.670 --> 05:58.480
within this very

138
05:58.480 --> 06:03.090
skill. And then we come down to the shell option, again, we supply a string
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

138
05:58.480 --> 06:03.090
skill. And then we come down to the shell option, again, we supply a string

139
06:03.090 --> 06:04.320
value. And this is going

140
06:04.320 --> 06:08.260
to allow us to specify the user's shell. So like I say, if perhaps you want to

141
06:08.260 --> 06:09.600
give the user a

142
06:09.600 --> 06:14.120
bond shell, which would be bin SH, you can supply this right here, or depending

143
06:14.120 --> 06:14.880
on the environment,

144
06:14.880 --> 06:19.200
maybe you want to specify a Z shell. But more commonly, most cases you're going

145
06:19.200 --> 06:19.920
to be supplying

146
06:19.920 --> 06:24.560
a bin bash shell. So these are just some of the options for the user module. If

147
06:24.560 --> 06:25.280
we just go back

148
06:25.280 --> 06:28.690
to Google, and if you just happened to search for Ansible group module, this

149
06:28.690 --> 06:29.520
now takes us to

150
06:29.520 --> 06:34.320
documentation for this particular module. So let's scroll on down. Once again,
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

150
06:29.520 --> 06:34.320
documentation for this particular module. So let's scroll on down. Once again,

151
06:34.320 --> 06:34.960
we can see this is

152
06:34.960 --> 06:38.160
part of Ansible Core. It has a built-in module. We're not going to have to

153
06:38.160 --> 06:39.600
install it via collection.

154
06:39.600 --> 06:42.410
And again, the synopsis tells us this is going to allow us to manage the

155
06:42.410 --> 06:43.840
presence of groups on a

156
06:43.840 --> 06:47.690
host. Similarly, just like with the user module, if we're dealing with Windows

157
06:47.690 --> 06:48.480
system with thinner

158
06:48.480 --> 06:52.570
topology, we would have to use a different module entirely of the Ansible

159
06:52.570 --> 06:53.360
Windows when

160
06:53.360 --> 06:57.360
group module. So again, we can specify particular values. We can specify saying

161
06:57.360 --> 06:58.240
this example here,

162
06:58.240 --> 07:01.700
the group ID, which is going to be an integer value. Here we have the name
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

162
06:58.240 --> 07:01.700
the group ID, which is going to be an integer value. Here we have the name

163
07:01.700 --> 07:02.880
parameter. Once again,

164
07:02.880 --> 07:06.480
this is going to be a string value. And this is required. Basically, we can't

165
07:06.480 --> 07:06.960
use a module

166
07:06.960 --> 07:12.200
without supplying this value. And scrolling on down, we can specify the actual

167
07:12.200 --> 07:13.360
state that is whether

168
07:13.360 --> 07:16.590
the group should actually be on the system, or whether it should be removed

169
07:16.590 --> 07:17.520
from the system. So

170
07:17.520 --> 07:21.050
basically, we can specify should the state be absent to remove a particular

171
07:21.050 --> 07:22.400
group, or we can specify

172
07:22.400 --> 07:26.340
the state that should be present to ensure that that group is valid and present

173
07:26.340 --> 07:27.280
on the system.

174
07:27.280 --> 07:30.480
So now that we've seen some of the documentation, let's get hands on by
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

174
07:27.280 --> 07:30.480
So now that we've seen some of the documentation, let's get hands on by

175
07:30.480 --> 07:32.320
creating some examples in.

176
07:32.320 --> 07:37.120
Okay, so let's create a little playbook called play one dot yml. And let's just

177
07:37.120 --> 07:38.000
go in and edit

178
07:38.000 --> 07:41.230
this. Let's go into insert mode. Let's have our three hyphens at the top. We're

179
07:41.230 --> 07:41.920
going to give this

180
07:41.920 --> 07:46.120
a name. I'll just call this play one testing the user module. Now the host I'm

181
07:46.120 --> 07:47.040
going to target,

182
07:47.040 --> 07:51.610
let's target the all groups will target both the yellow box and the blue box,

183
07:51.610 --> 07:51.920
and are

184
07:51.920 --> 07:55.840
specify my tasks I wanted to find here. So the first task is going to be use

185
07:55.840 --> 07:57.040
the user module.

186
07:57.040 --> 08:00.160
So what's the name of the actual module where we know it's going to be answer
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

186
07:57.040 --> 08:00.160
So what's the name of the actual module where we know it's going to be answer

187
08:00.160 --> 08:01.440
able built in

188
08:01.440 --> 08:05.840
user. And now we're going to specify our particular value. So what was the

189
08:05.840 --> 08:07.440
required parameter? Well,

190
08:07.440 --> 08:10.860
if you recall, that was the name parameter, pretty much we're going to have to

191
08:10.860 --> 08:11.680
supply the name of

192
08:11.680 --> 08:16.240
the user we want to create. So let's create a user called Fred. Okay, now the

193
08:16.240 --> 08:16.880
next thing I'm going

194
08:16.880 --> 08:21.570
to do is I'm going to specify which type of shell environment should Fred have.

195
08:21.570 --> 08:23.040
So I will say shell.

196
08:23.040 --> 08:27.020
In this case here, I will just give Fred a born shell. Okay, so a pretty

197
08:27.020 --> 08:28.480
limited shell. And let's

198
08:28.480 --> 08:34.290
also specify the user ID. So let's give Fred a value of 1099. Okay, so let's
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

198
08:28.480 --> 08:34.290
also specify the user ID. So let's give Fred a value of 1099. Okay, so let's

199
08:34.290 --> 08:35.840
just write and quit.

200
08:35.840 --> 08:40.120
And all I will do in fact, just before I do this, if I go into the essay pass w

201
08:40.120 --> 08:40.960
d file,

202
08:40.960 --> 08:44.800
we can see we have our nugget user or answerable user and our test user. But

203
08:44.800 --> 08:45.520
notice we do not

204
08:45.520 --> 08:49.760
have an account for Fred when we run this particular command, that should exist

205
08:49.760 --> 08:51.200
. Or I suppose I should

206
08:51.200 --> 08:54.620
more accurately say when we run this particular playbook, it should exist. So

207
08:54.620 --> 08:55.280
with that said,

208
08:55.280 --> 08:58.770
let's hit enter. And we are gathering facts. I should probably have set that to

209
08:58.770 --> 08:59.520
false to speed

210
08:59.520 --> 09:03.570
things up. But nevertheless, and as we can see here, we have used the user
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

210
08:59.520 --> 09:03.570
things up. But nevertheless, and as we can see here, we have used the user

211
09:03.570 --> 09:04.800
module and have a change

212
09:04.800 --> 09:08.130
on both of our devices. So what we want to now do is to confirm those changes.

213
09:08.130 --> 09:09.040
So let's go back

214
09:09.040 --> 09:13.450
here. And if I now cat the same file, look at the very bottom here, we have the

215
09:13.450 --> 09:14.880
user Fred. We have

216
09:14.880 --> 09:20.800
Fred's user ID. And we can see that the shell that Fred has is the SH shell.

217
09:20.800 --> 09:21.680
Now right now Fred

218
09:21.680 --> 09:24.600
does not actually have a password. Again, we'll talk about that later on. But

219
09:24.600 --> 09:25.280
if I just say so,

220
09:25.280 --> 09:29.950
go past wd on Fred's and I type in my admin password. And now I give Freddy

221
09:29.950 --> 09:30.880
password of
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

221
09:29.950 --> 09:30.880
password of

222
09:30.880 --> 09:35.360
like just say Fred one. And I'll also confirm it as Fred one. Now Fred has a

223
09:35.360 --> 09:36.400
password so we should

224
09:36.400 --> 09:40.810
be able to substitute user into Fred's. And if I type in Fred one, I can say

225
09:40.810 --> 09:41.680
who am I? And I can

226
09:41.680 --> 09:45.440
echo out my shell environment. And we can see here we actually do have a born

227
09:45.440 --> 09:46.400
shell indeed.

228
09:46.400 --> 09:50.560
Similarly, if we go to the blue box and cat the exit password file, once again,

229
09:50.560 --> 09:55.060
then the very bottom, we can indeed see we have creative Fred with the user ID

230
09:55.060 --> 09:55.760
and we have assigned

231
09:55.760 --> 09:59.580
a born shell to that account. So now that we understand the very basics of

232
09:59.580 --> 10:01.040
creating a user with
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

232
09:59.580 --> 10:01.040
creating a user with

233
10:01.040 --> 10:04.040
Let's now get hands on with the group module.
