1
00:00:00,980 --> 00:00:06,230
Hey folks, in this video we will continue running Ansible Ad Hoc Command.

2
00:00:06,230 --> 00:00:14,030
So this is going to be the part three of all the commands that we will be covering in the ad hoc topic.

3
00:00:14,270 --> 00:00:20,120
So the very first command for this video will be creating a user on local or remote clients.

4
00:00:20,120 --> 00:00:22,190
So of course we'll pick remote clients.

5
00:00:22,190 --> 00:00:26,360
So this will know if the user is created under remote clients.

6
00:00:26,360 --> 00:00:34,820
Again, if you are creating users under a remote client's very frequently, then I would say write a

7
00:00:34,820 --> 00:00:35,300
playbook.

8
00:00:35,300 --> 00:00:43,100
But if you are creating a user just one time and then you might come back to it a year or two years

9
00:00:43,100 --> 00:00:46,880
from later, then it's best that you use this ad hoc command.

10
00:00:46,880 --> 00:00:55,850
And the ad hoc command starts with ansible space, all for the target computers or the target host with

11
00:00:55,850 --> 00:01:01,040
minus m module with a user is the module and minus A is the option.

12
00:01:01,040 --> 00:01:03,860
Now name of the user will be met.

13
00:01:03,860 --> 00:01:07,100
Its home directory is going to be slash home slash J.

14
00:01:07,100 --> 00:01:15,800
Smith it's a shell environment that you want to define is bin bash and the state is present, meaning

15
00:01:15,800 --> 00:01:18,920
you want this user to be created.

16
00:01:19,400 --> 00:01:19,760
All right.

17
00:01:19,760 --> 00:01:23,120
So let's go to our Ansible control node.

18
00:01:23,540 --> 00:01:26,420
Here is our Ansible control node.

19
00:01:26,690 --> 00:01:29,630
So first before we create.

20
00:01:30,340 --> 00:01:32,000
Our user, Jay Smith.

21
00:01:32,050 --> 00:01:37,300
Let's verify if that Jay Smith user exists on our remote client.

22
00:01:37,300 --> 00:01:43,630
So we'll do as ID Jay Smith and it says no such user.

23
00:01:43,660 --> 00:01:44,220
Okay, good.

24
00:01:44,230 --> 00:01:51,610
So there's user does not exist, so run the command ansible all minus M for module.

25
00:01:51,610 --> 00:01:55,230
And the module we are using is usr minus A for option.

26
00:01:55,240 --> 00:02:01,450
Now the options are starting with name of the user is a Jay Smith.

27
00:02:01,570 --> 00:02:02,010
All right.

28
00:02:02,020 --> 00:02:04,900
The home directory for Jay Smith will be home.

29
00:02:04,930 --> 00:02:06,400
Jay Smith.

30
00:02:06,610 --> 00:02:07,170
Okay.

31
00:02:07,180 --> 00:02:11,350
And then the shell, the environment.

32
00:02:11,350 --> 00:02:12,760
Let's move this down.

33
00:02:13,900 --> 00:02:24,510
Shell equal bin bash and the state, which is do you want it to be deleted if it exists or if it found

34
00:02:24,520 --> 00:02:26,230
or do you want it to create it?

35
00:02:26,530 --> 00:02:33,580
So in order to create it, you have to put in the option or present, just like as if you want a package

36
00:02:33,580 --> 00:02:34,960
to be installed.

37
00:02:35,200 --> 00:02:35,560
All right.

38
00:02:35,560 --> 00:02:37,840
So let's go ahead and hit enter.

39
00:02:38,920 --> 00:02:40,390
It should create a J.

40
00:02:40,390 --> 00:02:43,690
Smith user to our remote client.

41
00:02:43,690 --> 00:02:45,430
All right, so we got the result back.

42
00:02:45,430 --> 00:02:51,310
Everything came back in yellow, meaning it has changed or it has applied the change that we wanted

43
00:02:51,310 --> 00:02:52,750
it to be applied.

44
00:02:52,870 --> 00:02:53,200
All right.

45
00:02:53,200 --> 00:03:00,670
So on our remote client, let's go in and type ID Smith again to make sure it is created.

46
00:03:00,670 --> 00:03:01,720
Yes, it is created.

47
00:03:01,720 --> 00:03:05,050
Assign the user ID, group ID, and it works perfectly.

48
00:03:05,050 --> 00:03:05,320
All right.

49
00:03:05,320 --> 00:03:11,560
Moving on to the next ad hoc command, which is to add a user to a different group.

50
00:03:11,560 --> 00:03:19,660
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.

51
00:03:19,660 --> 00:03:26,200
Then simply you could use the same module user and change and define the group as a different group.

52
00:03:26,200 --> 00:03:28,750
All right, so let's go to our control node.

53
00:03:28,750 --> 00:03:31,600
Clear the screen, ansible.

54
00:03:31,600 --> 00:03:33,850
All minus RM modules.

55
00:03:33,850 --> 00:03:46,000
Modules user will be used and the name for the user name is Jay Smith and the group I wanted to be I

56
00:03:46,000 --> 00:03:47,650
of saw in that group.

57
00:03:47,650 --> 00:03:48,160
All right.

58
00:03:48,160 --> 00:03:49,870
So it should be in that group.

59
00:03:49,870 --> 00:04:00,490
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,

60
00:04:00,490 --> 00:04:04,600
but it's group IDs thousand now because it's part of ISIL group.

61
00:04:04,600 --> 00:04:07,810
You see group ID and the group is 1000.

62
00:04:07,810 --> 00:04:08,680
I have salt.

63
00:04:08,830 --> 00:04:09,280
All right.

64
00:04:09,280 --> 00:04:09,760
Excellent.

65
00:04:09,760 --> 00:04:10,470
It worked.

66
00:04:10,570 --> 00:04:14,470
Now, moving on to the next ad hoc ansible command.

67
00:04:14,470 --> 00:04:22,060
Deleting a user on a remote client simply run the same, same command as if you were creating a user.

68
00:04:22,810 --> 00:04:26,650
But you just define state equal absent.

69
00:04:26,650 --> 00:04:32,320
If you wanted to create a user you put in present for removing a user or deleting a user, you have

70
00:04:32,320 --> 00:04:33,670
to put absent.

71
00:04:34,090 --> 00:04:37,510
All right, let's go to our control node.

72
00:04:37,570 --> 00:04:44,020
Let's clear the screen, head up, arrow keys so you can get the last command of creating the user.

73
00:04:44,020 --> 00:04:47,230
This is the last command of creating a user instead of present.

74
00:04:47,230 --> 00:04:48,940
Let's put absent.

75
00:04:49,060 --> 00:04:52,030
So it should remove that user.

76
00:04:52,750 --> 00:05:01,690
So while it's working on it, we'll go to our remote client and let's clear the screen and now type

77
00:05:01,780 --> 00:05:11,250
ID JS met and it says no such user beautiful it's our ad hoc command are continue to work as we wanted.

78
00:05:11,260 --> 00:05:16,600
Next one is if you wanted to delete a user, you could use this command as well.

79
00:05:16,600 --> 00:05:23,650
And that is the shell command of the Linux machine, that is Ansible all minus M.

80
00:05:23,680 --> 00:05:26,560
The module that you will use is the shell.

81
00:05:26,560 --> 00:05:34,570
So which is telling the shell environment or the Linux machine operating system is that you use your

82
00:05:34,570 --> 00:05:42,010
own command to delete the user and that own OS command is a user.

83
00:05:42,010 --> 00:05:52,810
DL And Jay Smith So if he had not ran this command, this one Ansible command and we if he and we would

84
00:05:52,810 --> 00:05:54,230
have run as user Dell J.

85
00:05:54,250 --> 00:05:57,700
Smith, then the result would have been the same.

86
00:05:57,700 --> 00:06:02,710
All right, good morning on getting system information from remote clients.

87
00:06:02,710 --> 00:06:08,650
So if you wanted to pull the system information, the OS, the hardware and anything for that matter,

88
00:06:08,650 --> 00:06:17,350
even network, then you could run simple ansible the target host minus m for module and setup is the

89
00:06:17,350 --> 00:06:21,400
module that you will use to pull the system information.

90
00:06:21,400 --> 00:06:25,330
It's very simple command and a very easy to remember of course.

91
00:06:25,330 --> 00:06:29,290
Ansible all minus hm module and setup.

92
00:06:29,290 --> 00:06:35,530
And then you're going to get the results you're going to see it's going to come splashing over the screen

93
00:06:35,700 --> 00:06:38,050
a whole lot of information.

94
00:06:38,050 --> 00:06:44,860
You could either output to a file so you could view it, but it has a lot of information right here.

95
00:06:44,860 --> 00:06:46,870
We started right here.

96
00:06:48,070 --> 00:06:49,810
And it's a success.

97
00:06:49,960 --> 00:06:50,510
Okay.

98
00:06:50,530 --> 00:06:53,230
It's pulling all the information.

99
00:06:53,260 --> 00:06:55,260
This is the IP address.

100
00:06:55,270 --> 00:06:58,810
This is a different IP address that is on the system as well.

101
00:06:58,810 --> 00:06:59,470
Ansible.

102
00:06:59,500 --> 00:07:03,390
IPV six address network information.

103
00:07:03,400 --> 00:07:06,340
It has the ISO information.

104
00:07:06,340 --> 00:07:14,590
Ansible Default Mac and Network Mac address, MTU Gateway and a lot of information as you go down.

105
00:07:14,590 --> 00:07:21,580
So of course we we do not have a lot of time to go through every single one of them, but please spend

106
00:07:21,580 --> 00:07:28,840
some time to understand the information that is being pulled to you by Ansible module setup.

107
00:07:29,350 --> 00:07:30,880
All right, moving on.

108
00:07:30,910 --> 00:07:37,030
You could do what you could do is you can run commands on the remote host without a shell module as

109
00:07:37,030 --> 00:07:37,360
well.

110
00:07:37,360 --> 00:07:39,400
For example, reboot client one.

111
00:07:39,400 --> 00:07:42,250
So here is a command ansible.

112
00:07:42,250 --> 00:07:45,970
Client one a dash, a SBN reboot.

113
00:07:45,970 --> 00:07:46,250
Yes.

114
00:07:46,250 --> 00:07:54,790
So if you wanted to run a command on a remote client, usually you define a module shell, but there

115
00:07:54,790 --> 00:07:59,650
are certain commands that you do not need to have a shell module for it.

116
00:07:59,650 --> 00:08:04,180
You could simply run straight with the option and the command name just like that.

117
00:08:04,180 --> 00:08:07,240
So if you go and run this command on your.

118
00:08:09,060 --> 00:08:09,870
Ansible.

119
00:08:09,870 --> 00:08:10,990
Control node.

120
00:08:11,010 --> 00:08:12,030
Ansible.

121
00:08:12,950 --> 00:08:16,850
And client one is, of course our client.

122
00:08:16,850 --> 00:08:21,610
So you could put it in the IP address, which is 10 to 53, 1.115.

123
00:08:21,620 --> 00:08:29,150
Or you could simply put all minus a and the command se been slash reboot.

124
00:08:29,150 --> 00:08:32,120
This should reboot our remote client.

125
00:08:32,300 --> 00:08:32,780
All right.

126
00:08:32,780 --> 00:08:36,230
So let's go quickly on a remote client and see if it is rebooting.

127
00:08:36,230 --> 00:08:38,510
Yes, it is the excellent.

128
00:08:38,510 --> 00:08:40,680
So it worked perfectly.

129
00:08:40,700 --> 00:08:44,110
Now, you notice right here it says failed to connect to host y association.

130
00:08:44,120 --> 00:08:45,140
Because why?

131
00:08:45,170 --> 00:08:47,020
Because it is rebooting, right?

132
00:08:47,030 --> 00:08:48,230
That's what it has.

133
00:08:48,230 --> 00:08:48,880
Normal.

134
00:08:48,890 --> 00:08:52,010
You could just simply ignore that it did.

135
00:08:52,010 --> 00:08:54,440
What is supposed to do is to reboot.

136
00:08:54,440 --> 00:08:59,600
Once it comes back up, then you run any command, then you will get a successful result.

137
00:08:59,750 --> 00:09:00,110
All right.

138
00:09:00,110 --> 00:09:07,490
So these are a few of the ad hoc commands you can run any of the ad hoc commands, even if you have

139
00:09:07,490 --> 00:09:13,970
a playbook for it, if you just wanted to run it quickly or if you wanted to run certain tasks within

140
00:09:13,970 --> 00:09:15,260
a playbook.
