Now that we have created a user, George, in our last playbook.
Now, what about the password that will be used to log into George?
Now, one thing you could do is you could go into your client as root and then you could change the
password for George.
But of course, this is going to be cumbersome again and you have to do it.
So many remote clients.
All right.
So what do we do?
We go back to Ansible to do that for us.
So the playbook in this video will add or update a password for user George.
Please note Ansible does not allow us to pass a clear text password through the user module.
So when we are in the editor and we are writing a playbook, we cannot specify a clear text password
inside of the module, so we have to pass it through the variable.
So we'll see that in a second.
So our playbook will look like this.
We'll do the editor and we'll name a change pass YAML file so it will have the name of the playbook,
the host where you want it to execute that playbook at the task.
The first, the name of the task is Change your password or whoever the user wanted to change the password,
it doesn't really matter.
This is just a simple text.
The module that we will be using is a user module, same module we use to create the user.
Now here you have to define the name.
Who is the user you're talking about?
You're talking about George.
All right.
What are we doing?
What?
What are the options, the parameters that we have to define for that module?
We have to update password.
So update, underscore password, colon space.
Always.
All right, now the password.
What do you want it to define or put the password as well?
Here are here is the exact syntax that you have to use.
Double code, curly braces, curly braces, space, new password.
Just this, just a variable.
If you put an update password or my password, this will be just a variable.
It is not the password itself.
Then pipe then put in password underscore hash.
This is the encryption to encrypt the password while the ansible is going to the remote client and updating
the password so the traffic cannot be visible to other users.
All right.
And the hash we are using is as a 512.
Make sure you're using the exact same syntax, then parentheses, parentheses, close space, curly
braces close, curly braces close and double code close.
All right.
To run this playbook, run the command as below.
This will input the new password variable.
This is the variable that will be used by our playbook.
And the command that we will use is Ansible Playbook and the Playbook name.
We all are familiar with this.
Now here are the extra parameters you have to specify dash, dash, extra dash bars, which is telling
the playbook that use extra variables which is new password.
This is the name of the variable we defined equal a, b, c, 1 to 3.
Now this is the password that I am choosing for the user.
George, you could pick any password of your choice, but whatever the password you are defining, you
have to write down right here.
When you're running this entire command, you cannot take this password and just put it in to your YAML
file and put it in here.
It won't work.
You have to define the variable and then pass it along to the variable in the command.
All right.
Let's go to our.
Control node and we are in at Ansible Playbooks directory.
We are logged in as route.
Let's do them ed change, pass yaml or whatever the name that you want to define.
Dash, dash, dash, name, add or update user password.
All right, host, where do you want to run that against all?
So we only have one remote client our tasks.
What do you want it to do?
Let's put the name of the task.
Change.
George.
Password.
User.
Now we're going to use the user module.
The name will be George.
Update underscore password.
This is the exact same syntax you have to use always.
And the password here will define double code.
Curly braces.
Space, new password.
This is the variable.
You could have any variable name that you want, but that variable name has to be the same exact right
here when we're running the command.
All right, then.
Password underscore hash.
And let's move it up a little.
So we'll see.
Hash parentheses, single code as a 512.
Single code, close parentheses, close space.
Double curly braces.
Close, curly braces closed and double code.
That's it.
It's just that simple.
Save your YAML file.
Now let's run the playbook.
Change.
Past YAML.
Now we define.
These option extra vars, which means extra variable and the variable name a new password.
And now what password do you want to give to George ABC The simple password 1 to 3.
But of course, I recommend that you pick a stronger password.
All right, go ahead and hit enter.
All right.
It's doing the play, the playbook, gathering information for the host and changed.
Okay.
To no error messages.
Beautiful.
I mean, it worked.
Now, to verify if it worked, let's go to our client.
Right here is our client.
Let's log in.
I'm logged in as route.
Or You know what?
Let's make it simple.
Let's cancel it and hit enter and log in as another user.
Okay.
Let's wait for the login screen to come back.
All right.
So now we have the login screen.
This is the user that I created during the OS install.
Now this is the user we created in the last playbook.
Now we have to click on this and put in the password that we define as using this playbook.
So that is a, b, c, one, two, three moment of truth.
Let's hit enter and let's see if it worked.
All right.
Looks like it did work.
Excellent.
All right.
So that's how you go ahead and change passwords to all the users.
I know a lot of companies have their password update policies.
Some of them have six months, some of them have a year password policy.
But whatever the policy is, you don't have to go into every machine and change the password.
That is very, very tedious work.
So you could use Ansible to do that for you.
Excellent.
Just to confirm, we are logged in to the right user.
You could do.
Who am I?
I am George.
Excellent.
All right, great.