Hey folks, in this video we will continue running Ansible Ad Hoc Command.
So this is going to be the part three of all the commands that we will be covering in the ad hoc topic.
So the very first command for this video will be creating a user on local or remote clients.
So of course we'll pick remote clients.
So this will know if the user is created under remote clients.
Again, if you are creating users under a remote client's very frequently, then I would say write a
playbook.
But if you are creating a user just one time and then you might come back to it a year or two years
from later, then it's best that you use this ad hoc command.
And the ad hoc command starts with ansible space, all for the target computers or the target host with
minus m module with a user is the module and minus A is the option.
Now name of the user will be met.
Its home directory is going to be slash home slash J.
Smith it's a shell environment that you want to define is bin bash and the state is present, meaning
you want this user to be created.
All right.
So let's go to our Ansible control node.
Here is our Ansible control node.
So first before we create.
Our user, Jay Smith.
Let's verify if that Jay Smith user exists on our remote client.
So we'll do as ID Jay Smith and it says no such user.
Okay, good.
So there's user does not exist, so run the command ansible all minus M for module.
And the module we are using is usr minus A for option.
Now the options are starting with name of the user is a Jay Smith.
All right.
The home directory for Jay Smith will be home.
Jay Smith.
Okay.
And then the shell, the environment.
Let's move this down.
Shell equal bin bash and the state, which is do you want it to be deleted if it exists or if it found
or do you want it to create it?
So in order to create it, you have to put in the option or present, just like as if you want a package
to be installed.
All right.
So let's go ahead and hit enter.
It should create a J.
Smith user to our remote client.
All right, so we got the result back.
Everything came back in yellow, meaning it has changed or it has applied the change that we wanted
it to be applied.
All right.
So on our remote client, let's go in and type ID Smith again to make sure it is created.
Yes, it is created.
Assign the user ID, group ID, and it works perfectly.
All right.
Moving on to the next ad hoc command, which is to add a user to a different group.
So if we want Jay Smith a user to not to be part of Jay Smith Group, I want it to be part of ISIL group.
Then simply you could use the same module user and change and define the group as a different group.
All right, so let's go to our control node.
Clear the screen, ansible.
All minus RM modules.
Modules user will be used and the name for the user name is Jay Smith and the group I wanted to be I
of saw in that group.
All right.
So it should be in that group.
Now let's go to our client and now type J Smith you will see that it is its user ID is 1000 to AJ Smith,
but it's group IDs thousand now because it's part of ISIL group.
You see group ID and the group is 1000.
I have salt.
All right.
Excellent.
It worked.
Now, moving on to the next ad hoc ansible command.
Deleting a user on a remote client simply run the same, same command as if you were creating a user.
But you just define state equal absent.
If you wanted to create a user you put in present for removing a user or deleting a user, you have
to put absent.
All right, let's go to our control node.
Let's clear the screen, head up, arrow keys so you can get the last command of creating the user.
This is the last command of creating a user instead of present.
Let's put absent.
So it should remove that user.
So while it's working on it, we'll go to our remote client and let's clear the screen and now type
ID JS met and it says no such user beautiful it's our ad hoc command are continue to work as we wanted.
Next one is if you wanted to delete a user, you could use this command as well.
And that is the shell command of the Linux machine, that is Ansible all minus M.
The module that you will use is the shell.
So which is telling the shell environment or the Linux machine operating system is that you use your
own command to delete the user and that own OS command is a user.
DL And Jay Smith So if he had not ran this command, this one Ansible command and we if he and we would
have run as user Dell J.
Smith, then the result would have been the same.
All right, good morning on getting system information from remote clients.
So if you wanted to pull the system information, the OS, the hardware and anything for that matter,
even network, then you could run simple ansible the target host minus m for module and setup is the
module that you will use to pull the system information.
It's very simple command and a very easy to remember of course.
Ansible all minus hm module and setup.
And then you're going to get the results you're going to see it's going to come splashing over the screen
a whole lot of information.
You could either output to a file so you could view it, but it has a lot of information right here.
We started right here.
And it's a success.
Okay.
It's pulling all the information.
This is the IP address.
This is a different IP address that is on the system as well.
Ansible.
IPV six address network information.
It has the ISO information.
Ansible Default Mac and Network Mac address, MTU Gateway and a lot of information as you go down.
So of course we we do not have a lot of time to go through every single one of them, but please spend
some time to understand the information that is being pulled to you by Ansible module setup.
All right, moving on.
You could do what you could do is you can run commands on the remote host without a shell module as
well.
For example, reboot client one.
So here is a command ansible.
Client one a dash, a SBN reboot.
Yes.
So if you wanted to run a command on a remote client, usually you define a module shell, but there
are certain commands that you do not need to have a shell module for it.
You could simply run straight with the option and the command name just like that.
So if you go and run this command on your.
Ansible.
Control node.
Ansible.
And client one is, of course our client.
So you could put it in the IP address, which is 10 to 53, 1.115.
Or you could simply put all minus a and the command se been slash reboot.
This should reboot our remote client.
All right.
So let's go quickly on a remote client and see if it is rebooting.
Yes, it is the excellent.
So it worked perfectly.
Now, you notice right here it says failed to connect to host y association.
Because why?
Because it is rebooting, right?
That's what it has.
Normal.
You could just simply ignore that it did.
What is supposed to do is to reboot.
Once it comes back up, then you run any command, then you will get a successful result.
All right.
So these are a few of the ad hoc commands you can run any of the ad hoc commands, even if you have
a playbook for it, if you just wanted to run it quickly or if you wanted to run certain tasks within
a playbook.