Now, throughout this skill, we have been learning different modules such as how
to use the user module.
Now recall, when we learned how to use this particular module earlier on within
this skill,
we did not actually set a password for our user.
Remember, we created the particular user and then via the command line manually
,
we went in and assigned a password for that user so they could effectively log
in.
What I now want to do in this particular video is to walk through how we can
actually handle this particular problem
when using the user module. WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
when using the user module.
So with that said, let's dig in and check it out.
Now, one thing to say about passwords is that they should be stored utilizing
their password hash.
Basically, this is a one-way function that is going to transform the clear text
into a formal ciphertext.
Pretty much when we type in our username and then supply the password,
the password should go through a particular hashing algorithm,
which is going to generate this particular hash and then the hash generated is
going to be compared
with the hash stored on the system.
If they match up, then you must have supplied the correct password. WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
If they match up, then you must have supplied the correct password.
So in this case here, what we want to do is we actually want to generate a
password hash.
Once we have done this, we can supply this password hash in with our Ansible
playbook,
which we can then use to create our passwords for our user.
So notice if you happen to go into the X8 shadow file, for example,
oh, and of course, this is going to require super user privileges.
So I'll use my pseudo command.
Take, for example, all of this data right here, what we're looking at is the
password hash WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
password hash
for the Ansible user, which as we know, the actual password itself is just
simply the word
Ansible in lowercase.
This is transformed and stored as this particular value here, this string.
Now, there are a couple of ways we can handle this particular issue.
Let's say I wanted to create a user called Matt and I wanted the user's
password to be Matt one.
Of course, this is a very bad password.
It's not good security, but just in the interest of keeping things simple,
let's just say that was a combination.
So what we want to do is we want to generate a hash of this particular password WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
So what we want to do is we want to generate a hash of this particular password
.
And then we will supply this value in to our Ansible playbook.
So let's check it out one way we can actually generate this particular hash
is directly via the command line utilizing Ansible.
So if I just say Ansible and I target the local host, which is my own local
machine,
that is the control mode.
And the module I'll use as a debug module because we just want to print out
something
and what I want to do is supply an argument.
And now I'm going to have my quotation marks.
Now, inside of here, I'm going to say MSG, which is the message is equal to. WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
Now, inside of here, I'm going to say MSG, which is the message is equal to.
And now I'm going to have my double curly braces.
Now, inside of here, what I'm going to do is I'm going to supply the actual
password
that I want to generate the hash for.
So within single quotations, I will say the password is going to be Matt one.
And what I want to do is I want to use the pipe command because I'm going to
use a filter.
And the Ansible filter that I'm going to use is one called password hash.
Now, inside of parentheses right here, what I'm going to do is specify the
actual hashing algorithm, WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
actual hashing algorithm,
which in my case here is going to be SHA 512.
And then I will close my parentheses.
And there we go.
So if I hit enter, look at this right here.
This is the actual password hash that has been generated for the password, Matt
one.
So what I'm going to do here is I'm going to copy this right now.
OK, so let's copy you.
And what I will do is I will create a new playbook.
So let's call this play number six dot YML.
So I'm going to insert mode, have my three hyphens at the top.
Let's give us a name.
I'll just say play six.
I'll just say testing passwords. WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
I'll just say testing passwords.
Now the hosts I will target will be the all group and gather facts.
Let's set that to false.
And now my tasks are going to be defined.
So the very first task is going to have a name.
So I'll just say create the user and add a password.
Cool.
So I'm going to use the answerable built in user module.
And what I'm going to supply is the name, which in my case here is going to be
Matt's.
And the password I'm going to supply.
I'll just use a variable value.
So I'll have my quotation marks and my double curly braces.
And the password I'm going to supply will be password. WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
And the password I'm going to supply will be password.
Now this is a variable value here.
So what I'm going to do is actually define those variables.
So let me just go up to the top right here and I'll just use the vars keyword.
And the variable I want to create is one called password.
OK.
Now inside of here within my quotation marks, all I'm going to do is I'm going
to paste in
that big long string.
Check this out.
If I just save this right here and I clear the screen and I just say answerable
playbook,
play six dot yml and to enter.
Oh, and clearly I've made a mistake.
Let's go back into this.
Notice I've written gather false. WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
Notice I've written gather false.
That should be gather facts and set the value to false.
That's a little bit of a silly mistake.
So I'll try that again.
Let's close the screen, arrow up and hit enter.
Try again.
And as we can see here, we have two changes on the devices.
So let's go and check this out then.
So we go to the yellow box.
If I cat, it's a pass WD, we can see we have the matte user now on the system.
And if I say pseudo cat, it's a shadow down the bottom here, we have all of
this encrypted
password.
So the big test is if I just clear the screen and I say SU matte to substitute WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
So the big test is if I just clear the screen and I say SU matte to substitute
user and I
now have to type in Matt's password.
Let's type in M A T T one.
Matt one.
OK.
So if I hit enter, look at this right here.
Who am I?
I am now Matt.
I was able to authenticate his mat using the mat one password.
And similarly, if I slide on over, let's go to the blue box.
Again, we should also have a user mat.
Let's try to substitute user.
If I type in Matt one and to enter, look at this right here.
We have also became the mat accounts.
Now, let me just show you one other way which we can use to handle this WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
Now, let me just show you one other way which we can use to handle this
particular problem.
So I'll just say them play seven dot Y mail.
So going to insert modes, give the play name.
I'll just set another way to create passwords.
The host is going to be the all group once again.
Gather facts as it falls.
And let me just define some variables right here.
Let me define a user variable.
Let's create a user called Shelly and we get a password called Shelly one.
And now create my tasks or just say create user accounts.
So the first thing I will do is I'll use the answer will built in user module. WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
So the first thing I will do is I'll use the answer will built in user module.
And the name I'm going to apply as the user here is going to be my user
variable.
So this task here will create the user Shelly.
And when that user is created, we want to set the password for the user.
So to say set the user's passwords.
And this time, what I'm going to do is use the answer will built in shell
module.
And all I'm going to do here is say echo.
And I'm going to take the password variable and I'm going to pipe that into the
pass WD
command and then say SEDN for standard in.
And then I'm going to supply the user that I want to apply this to. WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
And then I'm going to supply the user that I want to apply this to.
So basically what this will do, it will take the Shelly one password,
throw through the hashing algorithm and assign it to the user of Shelly right
here.
So let's escape colon WQ to write in quits.
Let's say answer will play book play seven dot YML and to enter.
Let's give it a moment.
And as we can see here, we have our changes.
So let's go to our devices to confirm.
So let's just do our cat of Etsy pass WD.
We can see we have the Shelly user down the bottom.
And if we cat the Etsy shadow, oh, of course, so do we need for that. WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
And if we cat the Etsy shadow, oh, of course, so do we need for that.
So so do cats, Etsy shadow.
And down the bottom here, check this out.
We actually have the hash password for Shelly.
So what I will do here is clear the screen and try to log in,
so I'll substitute user and become Shelly.
And if I type in Shelly one and to enter, look at this right here.
We have correctly authenticated as the Shelly user.
And the same thing is true over on the blue box device.