Okay, so let's get started on the solution.
So the very first time we're going to have to do it is to create three new
groups on both
of our managed devices called valid one, valid two and valid three.
So let's create our playbook, save them validation dot ymel, going to insert
mode,
have our three hyphens at the top.
Let's just give this a name, just call this validation playbook.
Now we're going to do this on all of our devices.
So the groups I'm going to target will be the all group and I don't need to
gather facts.
So I'll just set that to false.
And what I'm now going to do is I'm going to create my groups. WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
And what I'm now going to do is I'm going to create my groups.
So to specify my tasks and I'll give this a name or say create first group and
I'll use
the answerable built in group module.
And the name of the group is going to be valid one and the state is going to be
present.
Now in the interest of time, let me just copy this right here and I'll just
paste this in again.
All I will do is make some modifications.
I'll just say create the second group and I'll change this to valid two for the
group name.
And again, for the third group, let me just paste this in and I'll change this
to create
third group and the group will be called valid three. WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
third group and the group will be called valid three.
So that will ensure that we have our three groups created.
So now what I want to do is I want to create a user called valid user,
give them a Ben Bash shell and grant the account group access to the three
groups we just created.
So let's give this one a name or say creates user accounts.
I'm going to use the answerable built in user module this time.
The name is going to be valid underscore user.
The shell is going to be forward slash Ben forward slash bash
and now specify the groups that that user should be a member of. WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
and now specify the groups that that user should be a member of.
So the first group we're going to join is going to be valid one.
Then we'll have a comma to specify the next group, which is valid two,
then a comma and add valid three.
So the next task is going to be give the account a password.
So what I'm going to do here is use the answerable built in shell module
and I'll just echo out the password variable, which I haven't created yet.
I'll do that in a moment and I'll pipe that in to the past wd command,
specify s cd in and then feed in the user variable.
So like I say, we actually haven't defined these particular values. WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
So like I say, we actually haven't defined these particular values.
So what I will do is I'll go up to the very top right here and I'll define my
verse.
So I'll just create a variable called user and the user is going to be valid
user
and the password will as per the instruction, we're going to have to give a
password of nuggets.
So what I will do here is say nuggets.
And in fact, since we actually have a variable for valid user, let me go down
here.
And as opposed to hard coding this, I'll just use the variable value.
And now with that done, the last thing I'm going to have to do is to give this
user
support user privileges.
So let's give a name for the next task. WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
So let's give a name for the next task.
And we just give the user sudo paths.
So I'll use the answerable built in line and file module.
What is the path I want to manipulate?
You guessed it's going to be forward slash Etsy forward slash sudoers.
The line I'm going to add in this case here,
I would just say valid user.
And then within capital letters, I will say all is equal to and then open my
parentheses,
all colon all close parentheses and then just say all and capital letters again
and close my
quotations.
And then of course, for good practice, we're going to validate what we've just WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
And then of course, for good practice, we're going to validate what we've just
done.
So we'll use the command vice sudo -cf to check the file and then percentage is
to pass in the actual
file we're working with.
And where do we want to add this?
We're going to use the insert after parameter.
And they want to insert at the end of the file.
So with that now done, everything should be up and running.
So let's just press colon wq to write in quotes.
And I'll just say answerable -playbook validation.yaml and to answer.
Open appears we have a little bit of a syntax error.
And appears I have a slight indentation error. WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
And appears I have a slight indentation error.
Notice this?
This is the trick.
This is the trick of working with yaml.
So I'm going to have to knock it in one space.
So move that in and again down here.
Let's also fix the indentation.
Okay, so that should be the indentation fixed.
And run the playbook.
And appears everything has ran successfully.
So let's go to our devices.
So if I cat the ec group file right here, we can see we have added these three
groups
in valid user as a member of the three groups, which is a good sign.
Let's try to log in as a valid user.
So say su valid user and I'll type in the password nuggets. WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
So say su valid user and I'll type in the password nuggets.
And if I say who am I, we can see we are the valid user.
And if I just say sudo cat, ec sudoers, that should open up the sudoers file.
And I'll type in my password of nuggets to confirm.
Notice we have super user access.
And we can see here at the very end of the file we have indeed inserted the
information
for valid user to be a super user.
And again on blue box, let's cat ec group.
We can see valid user as a member of the three groups.
And again, we could also say id valid user to see that information. WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
And again, we could also say id valid user to see that information.
There are the three groups right there.
And let's substitute into the valid user, type in the password of nuggets.
We now see who am I.
And if I open up the ec sudoers file using the sudo command, we do have super
user access.
I'll type in the password nuggets and we can see here we can actually read that
file
using our elevated privileges and at the very bottom, there is the valid user
account.
And again, just to confirm, I can say sudo dnf updates.
And as we can see here, the command is available to us and we can just say why WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
And as we can see here, the command is available to us and we can just say why
and hit enter.
So that is us for our validation challenge.
I hope it's been informative for you and I'd like to thank you for viewing.