Imagine you have to create a user on hundreds of different Linux machines.
Are you going to log into each and every machine and create a user?
Well, if you do not have an automation system, then most likely, yes, you do have to do that and
it's going to take you a lot of time and it's not very productive.
That's when we have as well to automate that.
So you could create users on your Linux or remote clients or even Windows remote clients from a few
clicks.
And we'll create it to as many systems as you have defined in the host file.
So in this video, we are going to create a user on our remote client.
So the playbook that we will write is going to create a user.
George On a remote client, the user George will have a home directory as slash home slash George by
the way, just ignore this uppercase George.
It will have a lowercase g.
The shell environment for user will be for the user.
George will be slash bin and slash bash.
You could define other parameters of a user when you create a user in the YAML file.
All right.
So we will create the YAML file and name it.
Add user yaml, define the YAML parameters and define the name of the playbook.
Then host which host you want to run it on and the tasks.
This is all you are very familiar with right now.
I'm sure you could write all of this up to this point with your eyes closed, now comes the task and
what modules that you're going to be using first you need to create.
The name of the task is to create users and the module that we will use is user module.
If you want to know a lot different parameters that are using or options that are needed in the user
module, of course you could go to the docs dot ansible dot com website.
All right.
So the module is defined.
Now let's define the option with that module.
The first thing is the name.
What is the name that you want to give that user that you want to create?
What is the home directory?
We wanted to give it slash home and slash George.
And the third thing that we want to define, it's Shell.
We wanted to give it a shell slash spin and slash bash.
Now if you wanted to pick a different user ID, you want to pick a different group or different information
related to that user or even the description of the user.
You could put all of that in this under the user module with the options.
So right now we are just picking these three options.
And then once that is defined, what do we do?
We run our playbook by simply running add user dynamo with Ansible playbook.
All right, let's go right into our Linux remote client.
Let's make sure we do not have a user call.
George So let's do ID.
George and I will say no such user.
All right, let's do Kat on Etsy password just to make sure there is no such user in the etsy password.
There isn't any, but we could make it our search more specific by tapping it grep george etsy password
and there isn't anything.
Let's clear the screen.
All right, so let's go to our control node.
Let's write down.
The playbook.
All right.
So we are in the Playbook directory.
Good.
Let's do vim, add user or any name that you want to pick for that playbook.
Let's define it's a playbook.
Let's put the name of the playbook playbook for creating users.
All right.
Host It could be specific.
Host With the IP or host name or simply all.
Then the tasks.
And now the name of the task is to create users or user, then the module user.
Now comes the option of the module, the name of the user that you want to create.
George And the home directory of George will be home.
George and the shell that user should have.
The shell environment has been.
BASH All right.
It's just that simple.
Go ahead and save the file.
Now, let's go ahead and run our Ansible playbook.
And the playbook name is add user yaml.
Hit enter.
All right, playbook for creating uses as the name we define task for all.
And this is the IP address that was found inside of host file.
All right.
Anyway, it went to that host remote client and.
Okay, nothing.
No failure and change.
Meaning one change that we asked.
It means it created this user.
So our playbook ran and was successful.
Beautiful.
Now let's confirm on the client side.
So we'll do ID, George, and oops, let's put take out the slash at the end.
And there you go.
It's telling us the user ID has been created with George Group ID and groups.
Now let's do Kat.
On the password.
Let's see right here.
It's the George entry of the user.
Is there?
Nice.
Now let's see if it has a home directory.
Let's do KD slash home.
Let's do LS minus later.
And you notice it has two home directory.
One is the regular user, which is my user and then the George Home Directory which we just created
it.
It's time seven everything.
All right, so that's how you go and create a user's on your mobile client.
Now, if you are installing an application, an application requires that you create a user for that
application.
And of course, for that you have to do it for hundreds of Linux machines.
Then this playbook is going to come so handy and then you will be so thankful that you have access to
this playbook.