So now that we understand how to create users with passwords, what I now want
to do is to create
a user with a password but give that user super user access. So with that said,
let's just dive in.
So what I will do here is I will go and create a new playbook. Let's call this
play8.ymail
and we'll do the usual, have our three hyphens and let's call this playbook
play8.give super user
access. So the host again can target the all group in this case here. Let me
just target the
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
yellow box just for a little bit of variation and let's say gather facts is
false. So let me just
create some variables right here. I'll have the user. Let's call this user
Maria and Maria can have
a password of Maria one. Now let's create our tasks and the first task will be
create the user
accounts. So we use the Ansible built in user module and the name we're going
to supply is going
to be the user variable we just supplied. And now let's have another task. We
'll just say add
password to accounts. And again, we'll just use the Ansible built in shell
module like we did in the
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
previous video. And all I'll do is I'll echo out the password variable and I'll
pipe it into the
past wd command use sd in and then supply my user variable. Okay, so we're
going to create the user
here. Then the password for that user. Now what we want to do is you want to
effectively give that
user super user access. And as you may recall from the red hat certified system
admin exam,
the way we can do this is by modifying the sudoers file. So again, you can
template this out if you
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
so wish, but this would require a rather large ginger template. In my case here
, I just want to
add one line to a configuration file. So I'm going to take the easier option
and use the line and
file module we saw in a previous skill. So let's specify the name here, we'll
just say give the user
sudo-prevs and the module is going to be the Ansible built in line and file
module. Now what I'm
going to do here to specify the path to the actual file and the file this time
is going to be the
Etsy sudoers file. Now I'm going to specify the line I want to add. Now the
syntax is going to be
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
as follows. I'm going to specify the user, which in this case here is going to
be Maria. And again,
if you recall the syntax is as follows, we're going to say all equals and then
inside parentheses,
we'll say all colon all close parentheses and then all that is going to give us
super user access
completely for that particular user, Maria. And all I will do is close off my
quotation marks.
Now this part here really is important because we are modifying the sudoers
file, which is a very,
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
very important file. We don't want to effectively put in bad configuration. We
want to validate
that everything we've done is actually syntactically correct. Now ordinarily
via the command line,
we would use the vice sudo command to modify the sudoers file. We wouldn't just
do it with a regular
text editor. So we're going to use vice sudo to effectively check a particular
file. So what we're
going to do here, and I'm just going to say via sudo and then dash cf to check
a file. And I'm going
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
to substitute in the actual file that we have supplied using percentage s that
will tell
answerable to actually validate this particular file here. After we've modified
it. Now the question
actually is where do we want this particular entry to go in within the file? So
all I will do
is I'm going to use the insert after parameter, and I'm going to give the
option eOF. So pretty much
we want to insert this at the end of the file at the very bottom. So with that
now done, I'm going
to save the file and now I'll just say Ansible Playbook play eight dot yml and
to enter. Now we WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
to enter. Now we
create the account, give it a password and give the user super user privileges.
So what I will do
now is go to my yellow box and what I will do is I will substitute user to
Maria and I'll type
in the password Maria one. Okay, so we're now seem to have that access. What I
now want to do is to
test Maria's super user abilities can Maria use the sudo command. So as the
Maria account,
let's try to type something like say sudo dnf updates. So if I enter, we get a
little warning,
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
I'm going to have to type in Maria's password, which is Maria one. If I hit
enter, check this out,
but actually able to run this super user command. And if I hit Y and hit enter
again,
Notice the Supraiser task begins to execute as the user Maria.