WEBVTT

1
00:00.000 --> 00:03.840
So now that we understand how to create users with passwords, what I now want

2
00:03.840 --> 00:05.120
to do is to create

3
00:05.120 --> 00:10.570
a user with a password but give that user super user access. So with that said,

4
00:10.570 --> 00:12.000
let's just dive in.

5
00:12.000 --> 00:16.080
So what I will do here is I will go and create a new playbook. Let's call this

6
00:16.080 --> 00:18.080
play8.ymail

7
00:18.080 --> 00:21.920
and we'll do the usual, have our three hyphens and let's call this playbook

8
00:21.920 --> 00:23.920
play8.give super user

9
00:23.920 --> 00:27.490
access. So the host again can target the all group in this case here. Let me

10
00:27.490 --> 00:28.080
just target the

11
00:28.080 --> 00:32.220
yellow box just for a little bit of variation and let's say gather facts is
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

11
00:28.080 --> 00:32.220
yellow box just for a little bit of variation and let's say gather facts is

12
00:32.220 --> 00:33.360
false. So let me just

13
00:33.360 --> 00:36.970
create some variables right here. I'll have the user. Let's call this user

14
00:36.970 --> 00:38.320
Maria and Maria can have

15
00:38.320 --> 00:43.240
a password of Maria one. Now let's create our tasks and the first task will be

16
00:43.240 --> 00:44.320
create the user

17
00:44.320 --> 00:48.500
accounts. So we use the Ansible built in user module and the name we're going

18
00:48.500 --> 00:49.440
to supply is going

19
00:49.440 --> 00:53.250
to be the user variable we just supplied. And now let's have another task. We

20
00:53.250 --> 00:54.240
'll just say add

21
00:54.240 --> 00:58.060
password to accounts. And again, we'll just use the Ansible built in shell

22
00:58.060 --> 00:59.280
module like we did in the

23
00:59.280 --> 01:03.540
previous video. And all I'll do is I'll echo out the password variable and I'll
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

23
00:59.280 --> 01:03.540
previous video. And all I'll do is I'll echo out the password variable and I'll

24
01:03.540 --> 01:04.160
pipe it into the

25
01:04.160 --> 01:09.290
past wd command use sd in and then supply my user variable. Okay, so we're

26
01:09.290 --> 01:10.880
going to create the user

27
01:10.880 --> 01:15.650
here. Then the password for that user. Now what we want to do is you want to

28
01:15.650 --> 01:17.040
effectively give that

29
01:17.040 --> 01:21.740
user super user access. And as you may recall from the red hat certified system

30
01:21.740 --> 01:22.480
admin exam,

31
01:22.480 --> 01:27.400
the way we can do this is by modifying the sudoers file. So again, you can

32
01:27.400 --> 01:28.640
template this out if you

33
01:28.640 --> 01:32.430
so wish, but this would require a rather large ginger template. In my case here
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

33
01:28.640 --> 01:32.430
so wish, but this would require a rather large ginger template. In my case here

34
01:32.430 --> 01:33.440
, I just want to

35
01:33.440 --> 01:37.280
add one line to a configuration file. So I'm going to take the easier option

36
01:37.280 --> 01:38.480
and use the line and

37
01:38.480 --> 01:42.440
file module we saw in a previous skill. So let's specify the name here, we'll

38
01:42.440 --> 01:44.000
just say give the user

39
01:44.000 --> 01:48.590
sudo-prevs and the module is going to be the Ansible built in line and file

40
01:48.590 --> 01:49.760
module. Now what I'm

41
01:49.760 --> 01:53.020
going to do here to specify the path to the actual file and the file this time

42
01:53.020 --> 01:53.840
is going to be the

43
01:53.840 --> 01:58.450
Etsy sudoers file. Now I'm going to specify the line I want to add. Now the

44
01:58.450 --> 01:59.600
syntax is going to be

45
01:59.600 --> 02:04.270
as follows. I'm going to specify the user, which in this case here is going to
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

45
01:59.600 --> 02:04.270
as follows. I'm going to specify the user, which in this case here is going to

46
02:04.270 --> 02:05.360
be Maria. And again,

47
02:05.360 --> 02:10.300
if you recall the syntax is as follows, we're going to say all equals and then

48
02:10.300 --> 02:11.760
inside parentheses,

49
02:11.760 --> 02:16.820
we'll say all colon all close parentheses and then all that is going to give us

50
02:16.820 --> 02:17.840
super user access

51
02:17.840 --> 02:21.980
completely for that particular user, Maria. And all I will do is close off my

52
02:21.980 --> 02:23.200
quotation marks.

53
02:23.200 --> 02:27.440
Now this part here really is important because we are modifying the sudoers

54
02:27.440 --> 02:28.320
file, which is a very,

55
02:28.320 --> 02:32.990
very important file. We don't want to effectively put in bad configuration. We
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

55
02:28.320 --> 02:32.990
very important file. We don't want to effectively put in bad configuration. We

56
02:32.990 --> 02:34.320
want to validate

57
02:34.320 --> 02:38.800
that everything we've done is actually syntactically correct. Now ordinarily

58
02:38.800 --> 02:39.760
via the command line,

59
02:39.760 --> 02:43.600
we would use the vice sudo command to modify the sudoers file. We wouldn't just

60
02:43.600 --> 02:44.480
do it with a regular

61
02:44.480 --> 02:49.610
text editor. So we're going to use vice sudo to effectively check a particular

62
02:49.610 --> 02:50.720
file. So what we're

63
02:50.720 --> 02:55.870
going to do here, and I'm just going to say via sudo and then dash cf to check

64
02:55.870 --> 02:57.040
a file. And I'm going

65
02:57.040 --> 03:01.830
to substitute in the actual file that we have supplied using percentage s that
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

65
02:57.040 --> 03:01.830
to substitute in the actual file that we have supplied using percentage s that

66
03:01.830 --> 03:02.320
will tell

67
03:02.320 --> 03:06.480
answerable to actually validate this particular file here. After we've modified

68
03:06.480 --> 03:07.520
it. Now the question

69
03:07.520 --> 03:12.270
actually is where do we want this particular entry to go in within the file? So

70
03:12.270 --> 03:13.600
all I will do

71
03:13.600 --> 03:17.620
is I'm going to use the insert after parameter, and I'm going to give the

72
03:17.620 --> 03:19.440
option eOF. So pretty much

73
03:19.440 --> 03:23.840
we want to insert this at the end of the file at the very bottom. So with that

74
03:23.840 --> 03:24.720
now done, I'm going

75
03:24.720 --> 03:29.280
to save the file and now I'll just say Ansible Playbook play eight dot yml and

76
03:29.280 --> 03:30.320
to enter. Now we
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

76
03:29.280 --> 03:30.320
to enter. Now we

77
03:30.320 --> 03:34.310
create the account, give it a password and give the user super user privileges.

78
03:34.310 --> 03:35.280
So what I will do

79
03:35.280 --> 03:39.530
now is go to my yellow box and what I will do is I will substitute user to

80
03:39.530 --> 03:40.480
Maria and I'll type

81
03:40.480 --> 03:45.220
in the password Maria one. Okay, so we're now seem to have that access. What I

82
03:45.220 --> 03:46.240
now want to do is to

83
03:46.240 --> 03:50.930
test Maria's super user abilities can Maria use the sudo command. So as the

84
03:50.930 --> 03:51.920
Maria account,

85
03:51.920 --> 03:57.120
let's try to type something like say sudo dnf updates. So if I enter, we get a

86
03:57.120 --> 03:57.680
little warning,

87
03:57.680 --> 04:01.260
I'm going to have to type in Maria's password, which is Maria one. If I hit
WEBVTT
X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000

87
03:57.680 --> 04:01.260
I'm going to have to type in Maria's password, which is Maria one. If I hit

88
04:01.260 --> 04:02.560
enter, check this out,

89
04:02.560 --> 04:06.850
but actually able to run this super user command. And if I hit Y and hit enter

90
04:06.850 --> 04:07.440
again,

91
04:07.440 --> 04:12.240
Notice the Supraiser task begins to execute as the user Maria.
