1
00:00:01,080 --> 00:00:04,490
In this video, we will be running ansible ad hoc commands.

2
00:00:04,500 --> 00:00:09,180
Now, of course we will be covering quite a few different ad hoc commands.

3
00:00:09,190 --> 00:00:15,660
So what I have done is I have divided this video into different parts.

4
00:00:16,500 --> 00:00:22,020
Now here is the part one where you cover a few commands of ad hoc.

5
00:00:22,830 --> 00:00:28,800
All right, first thing, first ad hoc commands run on as needed basis.

6
00:00:28,950 --> 00:00:33,570
And usually for those tasks that do not repeat.

7
00:00:34,380 --> 00:00:43,320
If you repeat some of your tasks frequently, then it's better that you create playbooks for those tasks.

8
00:00:43,890 --> 00:00:46,050
All right, so let's take an example.

9
00:00:46,050 --> 00:00:47,710
Syntax for ad hoc.

10
00:00:47,730 --> 00:00:49,840
Ansible Command are as follows.

11
00:00:50,010 --> 00:00:50,940
It's just.

12
00:00:50,940 --> 00:01:00,480
Ansible So you don't run Ansible Dash Playbook Command, because with that command you have to specify

13
00:01:00,720 --> 00:01:03,390
the playbook, location or the file.

14
00:01:03,420 --> 00:01:09,270
So since this is an ad hoc command, we will just use a simple ansible command.

15
00:01:09,510 --> 00:01:12,060
All right, then, ansible space.

16
00:01:12,090 --> 00:01:14,670
The target, which means aware.

17
00:01:14,670 --> 00:01:17,100
On which system do you want to run?

18
00:01:17,130 --> 00:01:26,220
This ad command could be either or all so all meaning it will go to your etsi ansible host file and

19
00:01:26,220 --> 00:01:31,560
all the targets, all the remote clients listed there will be targeted.

20
00:01:32,310 --> 00:01:39,150
Or if you have aliases there or if you have a grouping there, you could define a right here.

21
00:01:39,750 --> 00:01:47,420
All right, then comes the minus or hyphen M, which is the option for module?

22
00:01:47,430 --> 00:01:47,910
Yes.

23
00:01:47,970 --> 00:01:53,490
You specify the module right here, which module you will be using to execute that task.

24
00:01:53,760 --> 00:01:57,630
Then come minus a, which is the module option.

25
00:01:57,630 --> 00:01:59,760
What exactly you're doing with it.

26
00:02:00,360 --> 00:02:00,820
All right.

27
00:02:00,840 --> 00:02:07,170
If you notice here, there is no minus a so there is no option for name.

28
00:02:07,170 --> 00:02:11,460
Here you can specify the name, but there is no reason to put the name.

29
00:02:11,460 --> 00:02:18,000
It's better to put the name of your task inside of the playbook so you would know exactly what this

30
00:02:18,000 --> 00:02:22,620
playbook is doing, or when you are running it, you will see which step it's on.

31
00:02:23,160 --> 00:02:23,550
All right.

32
00:02:23,550 --> 00:02:30,780
So here are the list of examples for Ansible add commands and the very first command that we will run

33
00:02:30,780 --> 00:02:37,260
as ad hoc command is the ping command ping, the local host.

34
00:02:37,680 --> 00:02:43,800
And if you are pinging the local host without a playbook, which I have covered previously and I'm sure

35
00:02:43,800 --> 00:02:45,880
you remember, it's just that simple.

36
00:02:45,900 --> 00:02:53,970
Ansible Space local host space minus M for module and space.

37
00:02:53,970 --> 00:02:54,870
And what do you want?

38
00:02:54,900 --> 00:02:56,250
Which module you want to run?

39
00:02:56,250 --> 00:02:58,890
And the name of the module is Ping.

40
00:02:59,070 --> 00:03:07,440
All right, so let's go to our Ansible control node and run this ad hoc example command onto our machine.

41
00:03:08,220 --> 00:03:12,000
All right, so right here, our control node is up and running.

42
00:03:12,000 --> 00:03:15,930
I'm going to open up the terminal window.

43
00:03:17,670 --> 00:03:27,720
And simply we'll run this ad hoc command ansible local host minus M4 module and which module we are

44
00:03:27,720 --> 00:03:28,200
using.

45
00:03:28,200 --> 00:03:31,740
We are using a ping module and this is the attached command.

46
00:03:31,740 --> 00:03:39,330
You do not need any playbook here you have the result local host to the success is the return code that

47
00:03:39,330 --> 00:03:48,810
you have and ping and pong and everything looks green, which means has no red fonts or anything response

48
00:03:48,810 --> 00:03:49,290
in red.

49
00:03:49,290 --> 00:03:52,740
So nothing happened to that ad hoc command.

50
00:03:53,280 --> 00:03:53,610
All right.

51
00:03:53,610 --> 00:03:54,540
Let's move on.

52
00:03:55,310 --> 00:04:01,460
The next ad hoc command will be creating a file on all remote clients.

53
00:04:01,490 --> 00:04:12,290
All right, so ansible space all for all the clients in at CES will host file and the module will be

54
00:04:12,290 --> 00:04:14,150
used with minus m option.

55
00:04:14,150 --> 00:04:23,450
The module name is file and minus a four module options, which is the path where it's going to create

56
00:04:23,930 --> 00:04:24,590
the file.

57
00:04:24,590 --> 00:04:32,570
The location of the file and the state is to create with the touch and the change mod r permissions

58
00:04:32,570 --> 00:04:34,040
will be 700.

59
00:04:34,400 --> 00:04:34,670
All right.

60
00:04:34,670 --> 00:04:36,470
Let's go to our.

61
00:04:38,270 --> 00:04:39,040
Sorry.

62
00:04:39,050 --> 00:04:40,850
Our Ansible node.

63
00:04:41,730 --> 00:04:44,940
And let's run this command and symbol.

64
00:04:45,870 --> 00:04:47,460
All and for all.

65
00:04:47,490 --> 00:04:48,810
What do we have?

66
00:04:48,810 --> 00:04:49,530
And all?

67
00:04:49,530 --> 00:04:52,710
Once again, let's check CAD at sea.

68
00:04:53,040 --> 00:04:55,230
Let's do more at sea.

69
00:04:55,230 --> 00:04:56,250
Ansible.

70
00:04:57,540 --> 00:04:58,680
And hosts.

71
00:04:59,530 --> 00:05:03,790
Then we have 10 to 53 1.115.

72
00:05:03,790 --> 00:05:06,250
This is the IP address.

73
00:05:06,280 --> 00:05:07,840
We have our for remote client.

74
00:05:07,850 --> 00:05:16,480
So let's first ping it to make sure it is payable 150 3115 because you never know the IP can change

75
00:05:16,480 --> 00:05:20,710
since we are running a remote client which is right here on DHCP.

76
00:05:20,740 --> 00:05:21,100
All right.

77
00:05:21,100 --> 00:05:31,780
So it is being able clear the screen and symbol all minus m file minus a option double code the path.

78
00:05:31,780 --> 00:05:34,810
Where do you want to create that file home.

79
00:05:34,810 --> 00:05:38,020
I absol and call it ad hoc one.

80
00:05:38,020 --> 00:05:38,650
All right.

81
00:05:38,800 --> 00:05:39,820
That's what we did.

82
00:05:40,180 --> 00:05:41,530
That's minimized this.

83
00:05:41,710 --> 00:05:46,660
Let's move this right here and let's move this down so we could see it.

84
00:05:46,960 --> 00:05:48,100
The complete command.

85
00:05:48,100 --> 00:05:48,610
All right.

86
00:05:48,610 --> 00:05:52,390
So that's the name of the file and the location.

87
00:05:52,390 --> 00:06:00,430
Now, the state you wanted to create using the touch command and the mod, meaning the permission.

88
00:06:00,430 --> 00:06:04,120
Let's put it 700 and let's run the command.

89
00:06:04,120 --> 00:06:05,440
Let's move up.

90
00:06:06,160 --> 00:06:15,340
And while it's running, we got the yellow messages back, which means it has changed what we have asked

91
00:06:15,340 --> 00:06:15,690
for it.

92
00:06:15,700 --> 00:06:21,400
So right here is changed, destination is created and all the other information that you need.

93
00:06:21,400 --> 00:06:26,080
So let's go to our remote client.

94
00:06:26,170 --> 00:06:28,330
Let's go to open terminal.

95
00:06:30,350 --> 00:06:31,610
All right, right here.

96
00:06:31,610 --> 00:06:33,200
We'll go to home.

97
00:06:33,210 --> 00:06:37,790
I have soul, and we'll see if it created ad hoc one.

98
00:06:38,920 --> 00:06:39,520
File.

99
00:06:40,490 --> 00:06:46,340
Right here is the ad hoc one file created by root because we ran the command route and we gave it the

100
00:06:46,340 --> 00:06:52,610
700 permission, which is read, write, execute only for its own self.

101
00:06:53,660 --> 00:06:54,530
Beautiful.

102
00:06:54,560 --> 00:06:55,010
All right.

103
00:06:55,010 --> 00:06:58,040
Let's go to the second ad hoc command.

104
00:06:58,130 --> 00:07:01,190
Deleting a file on all remote clients.

105
00:07:01,190 --> 00:07:06,860
So if you want to delete the same file, you can run the same command or same module for the command,

106
00:07:06,860 --> 00:07:07,790
which is file.

107
00:07:07,790 --> 00:07:11,270
But instead of state, you put touch, you put it absent.

108
00:07:11,630 --> 00:07:16,130
All right, let's go into our Ansible control node.

109
00:07:16,610 --> 00:07:20,240
Hit up arrow key simply to bring back the last command.

110
00:07:20,510 --> 00:07:27,490
And here, get rid of everything until state equal and put absent.

111
00:07:27,500 --> 00:07:29,870
This will allow us to delete a file.

112
00:07:29,870 --> 00:07:35,930
So many times you're going to see issues in your multiple servers which you want, where you want to

113
00:07:35,930 --> 00:07:42,140
delete one file, and of course you don't want to write a playbook for it, then you just run it as

114
00:07:42,140 --> 00:07:43,250
an ad hoc command.

115
00:07:43,250 --> 00:07:43,490
All right.

116
00:07:43,490 --> 00:07:49,780
So we want ad hoc zero one file that we created in our last step to be deleted.

117
00:07:49,790 --> 00:07:50,150
All right.

118
00:07:50,150 --> 00:07:51,950
So it's just that simple.

119
00:07:52,040 --> 00:07:55,750
Hit enter and it should take care of it.

120
00:07:55,760 --> 00:07:59,750
Let's verify it on our client.

121
00:07:59,780 --> 00:08:02,780
Let's do LS minus LTR again right here.

122
00:08:02,780 --> 00:08:08,450
When we ran it earlier, the file was there list run it again and the file is gone.

123
00:08:08,600 --> 00:08:10,640
So it did delete it.

124
00:08:11,210 --> 00:08:12,440
All right, next move.

125
00:08:12,470 --> 00:08:14,410
Let's move on to the next command.

126
00:08:14,420 --> 00:08:17,690
Copy a file to remote clients.

127
00:08:17,870 --> 00:08:20,480
So copy from one location to another.

128
00:08:20,480 --> 00:08:20,960
Right.

129
00:08:21,140 --> 00:08:26,970
So we will copy a file from our control node to our remote client.

130
00:08:27,720 --> 00:08:33,810
All right, so the copy will use the copy module and for the option, the source.

131
00:08:33,810 --> 00:08:36,840
Where do we copy it from?

132
00:08:37,160 --> 00:08:41,970
I have it in slash temp and we have it as ad hoc and destination.

133
00:08:41,970 --> 00:08:45,120
So let's go to our Ansible control node.

134
00:08:45,300 --> 00:08:48,690
The first thing we'll do will create the file.

135
00:08:48,690 --> 00:08:56,130
So we'll go to temp and we'll create it with the touch command ad hoc to.

136
00:08:56,520 --> 00:08:58,920
All right, the file is created right here is the file.

137
00:08:58,920 --> 00:09:00,420
Let's put something in that file.

138
00:09:00,420 --> 00:09:01,470
So, Echo.

139
00:09:03,600 --> 00:09:06,430
This is so echo.

140
00:09:06,540 --> 00:09:08,640
Let me put this in code.

141
00:09:09,760 --> 00:09:11,650
This is.

142
00:09:13,000 --> 00:09:16,090
And ad hoc.

143
00:09:16,780 --> 00:09:18,010
Test file.

144
00:09:18,040 --> 00:09:18,820
All right.

145
00:09:19,270 --> 00:09:24,520
And then I'll put that to our ad hoc to file that we just created.

146
00:09:24,760 --> 00:09:27,670
Let's confirm the content is in there.

147
00:09:27,670 --> 00:09:28,600
Ad hoc.

148
00:09:29,020 --> 00:09:30,260
Yes, it is in there.

149
00:09:30,280 --> 00:09:31,750
All right, so now we have a file.

150
00:09:31,750 --> 00:09:39,550
Now we need to copy that file over to our remote client so we will run our ad hoc command.

151
00:09:39,550 --> 00:09:46,300
And that would be Ansible all for all the clients that is Ansible file.

152
00:09:46,410 --> 00:09:46,870
Sorry.

153
00:09:46,900 --> 00:09:51,220
Host Well, and we'll use the copy module option.

154
00:09:51,220 --> 00:09:52,210
The source.

155
00:09:54,290 --> 00:09:57,680
Slash temp slash ad hoc two.

156
00:09:58,370 --> 00:10:00,910
And then the destination.

157
00:10:00,920 --> 00:10:02,090
Where do you want it?

158
00:10:02,090 --> 00:10:03,230
To copy it.

159
00:10:04,190 --> 00:10:08,800
Home Ihev saw an ad hoc, of course, for you.

160
00:10:08,810 --> 00:10:11,930
You'll put your username instead of my username.

161
00:10:12,020 --> 00:10:14,780
All right, so let's do that and hit enter.

162
00:10:15,230 --> 00:10:16,730
All right, moment of truth.

163
00:10:16,730 --> 00:10:19,820
Let's cross the finger and let's hope it copies over.

164
00:10:19,820 --> 00:10:22,550
We got the yellow font back.

165
00:10:22,550 --> 00:10:24,470
The color of the font.

166
00:10:24,500 --> 00:10:27,140
So which means it has changed.

167
00:10:27,140 --> 00:10:27,740
It worked.

168
00:10:27,740 --> 00:10:30,320
Nothing in a red, so nothing failed.

169
00:10:30,440 --> 00:10:32,630
Let's check on our.

170
00:10:33,750 --> 00:10:34,710
Remote client.

171
00:10:35,220 --> 00:10:43,340
Here we are in slash home, slash of and let's see if it copied over the file it did ad hoc to.

172
00:10:43,350 --> 00:10:43,710
All right.

173
00:10:43,710 --> 00:10:50,580
Let's confirm if this is the same file by doing CAD ad hoc and see if it has the same content that we

174
00:10:50,580 --> 00:10:55,140
added in our control node and it does have a same content.

175
00:10:55,140 --> 00:10:56,940
This is an ad hoc test.

176
00:10:56,950 --> 00:10:59,580
Well, that's just awesome.

177
00:10:59,580 --> 00:11:07,500
How we could run ad out commands on our multiple remote clients to perform a single task that is not

178
00:11:07,500 --> 00:11:08,490
needed later on.

179
00:11:08,850 --> 00:11:09,450
All right.

180
00:11:10,050 --> 00:11:11,400
I'll see you in the next part.
