1 00:00:00,710 --> 00:00:02,600 Hey, folks, welcome back. 2 00:00:02,930 --> 00:00:09,740 In this video, we will be installing and starting up a package in a Linux machine. 3 00:00:09,740 --> 00:00:16,280 So the very first thing is we'll pick a name for the YAML file, which we are creating for our playbook. 4 00:00:16,970 --> 00:00:22,930 Then defining the dash, dash, dash, which tells us that this is going to be a YAML file. 5 00:00:22,940 --> 00:00:29,670 Now the name of the playbook installing and running Apache or installing and running HTTP de. 6 00:00:29,690 --> 00:00:32,480 That's the name of the package of the Apache. 7 00:00:32,780 --> 00:00:37,460 All right, the host, where do you want to install and run this Apache package? 8 00:00:37,490 --> 00:00:39,410 You want to run it on a local host. 9 00:00:39,410 --> 00:00:39,800 All right. 10 00:00:39,800 --> 00:00:46,130 The tasks the third thing, what exactly we're doing, the name is that at this time, we will install 11 00:00:46,130 --> 00:00:47,780 Apache or HTTP. 12 00:00:48,830 --> 00:00:49,430 All right. 13 00:00:49,460 --> 00:00:53,900 Tell me the module that you will use to do that installation. 14 00:00:53,900 --> 00:00:56,900 We'll use the Yum module. 15 00:00:57,170 --> 00:00:57,560 All right. 16 00:00:57,560 --> 00:00:58,970 Or you could use DNF. 17 00:00:58,970 --> 00:00:59,420 All right. 18 00:00:59,420 --> 00:01:02,740 The name of the package will be a HTTP feed. 19 00:01:02,780 --> 00:01:09,740 Now, this is the exact name that you will use as if you are running yum install followed by the package 20 00:01:09,740 --> 00:01:12,970 name or DNF install followed by HTTP. 21 00:01:13,460 --> 00:01:16,070 This has to match with that package. 22 00:01:16,250 --> 00:01:16,640 All right. 23 00:01:16,640 --> 00:01:19,640 So once we have it, what do you want it to do with this? 24 00:01:19,640 --> 00:01:26,600 So we know you want to the name is a general information you want to install package and we will be 25 00:01:26,600 --> 00:01:27,590 using Yum command. 26 00:01:27,590 --> 00:01:34,250 But we could also do remove using Yum command and we could also do a lot a lot of other functions with 27 00:01:34,250 --> 00:01:34,700 Yum. 28 00:01:34,700 --> 00:01:37,220 So what exactly wanted to do with this package? 29 00:01:37,880 --> 00:01:47,540 We wanted to use the state as present, which tells the Ansible executables that we wanted it to be 30 00:01:47,540 --> 00:01:48,890 installed. 31 00:01:49,100 --> 00:01:51,690 So the package name is HTTP PD. 32 00:01:51,710 --> 00:01:59,480 And when you put in the state and and you define the state as present, it means that we want the package 33 00:01:59,480 --> 00:02:00,350 to be installed. 34 00:02:00,830 --> 00:02:01,760 Beautiful. 35 00:02:02,000 --> 00:02:05,960 Now the next thing is package is installed. 36 00:02:05,960 --> 00:02:11,150 Now we want to start the package, the service of the package to be started. 37 00:02:11,360 --> 00:02:17,840 For that, we have to give it a new name for that task and that is start http dx. 38 00:02:18,200 --> 00:02:27,830 Now if you notice, that name is exactly under the same vertical column of the name of the first name 39 00:02:27,830 --> 00:02:29,510 where we have the install package. 40 00:02:30,050 --> 00:02:30,500 All right. 41 00:02:30,500 --> 00:02:40,130 Then the module that we will be using to start the service is the service module and the name for what 42 00:02:40,130 --> 00:02:40,910 package. 43 00:02:41,000 --> 00:02:43,730 For that service we want to install is start. 44 00:02:43,730 --> 00:02:45,010 That is http. 45 00:02:45,950 --> 00:02:46,430 All right. 46 00:02:46,430 --> 00:02:53,600 Now, the state the state here is different than installing it and that is started. 47 00:02:54,320 --> 00:02:59,720 These are the few things that you have to remember if you do not remember these options and you could 48 00:02:59,720 --> 00:03:04,340 go back to the documentation and go to the module for Yum! 49 00:03:04,340 --> 00:03:06,380 Or go to the module for service. 50 00:03:06,380 --> 00:03:11,870 And then you could see what are the options that are available to you and whether you should use the 51 00:03:11,870 --> 00:03:16,340 state started or stop or present where you should use it and where you should not. 52 00:03:16,730 --> 00:03:17,240 All right. 53 00:03:17,750 --> 00:03:18,800 That's about it. 54 00:03:18,800 --> 00:03:25,610 This entire playbook is going to be installing the HTTP package and starting up its service. 55 00:03:26,330 --> 00:03:32,840 Now, once this playbook is completed and saved, then we'll go ahead and run the pack, install the 56 00:03:33,030 --> 00:03:34,850 YAML file. 57 00:03:35,180 --> 00:03:41,510 All right, so let's go to our Linux machine right here and let's log in as root. 58 00:03:43,280 --> 00:03:43,580 All right. 59 00:03:43,580 --> 00:03:50,360 So we are in our home directory, which is at Ansible Playbooks, which is the directory we are using 60 00:03:50,360 --> 00:03:52,280 to keep all of our playbooks. 61 00:03:52,340 --> 00:03:53,630 Who am I? 62 00:03:53,660 --> 00:03:55,250 I am logged in as root. 63 00:03:55,280 --> 00:03:56,450 All right, perfect. 64 00:03:56,480 --> 00:04:04,450 Now let's go ahead and create the YAML file and we are naming it pack install or ensure package install 65 00:04:04,700 --> 00:04:05,330 yaml. 66 00:04:06,050 --> 00:04:06,800 Hit enter. 67 00:04:07,280 --> 00:04:08,330 Now define dash. 68 00:04:08,330 --> 00:04:08,630 Dash. 69 00:04:08,630 --> 00:04:09,290 Dash. 70 00:04:11,510 --> 00:04:13,100 Dash name. 71 00:04:15,110 --> 00:04:17,720 Installing and running. 72 00:04:18,830 --> 00:04:22,280 Apache or http. 73 00:04:22,530 --> 00:04:24,020 DD That's fine. 74 00:04:24,470 --> 00:04:26,420 Now, where do you want it to run? 75 00:04:26,450 --> 00:04:29,450 We want it to run it on local hosts. 76 00:04:29,870 --> 00:04:30,380 All right. 77 00:04:30,380 --> 00:04:37,250 The tasks, what you want it to do, you want it to, first of all, give it a name of the task. 78 00:04:37,250 --> 00:04:44,000 By the way, if you don't give a name for a task that is still fine, the Ansible would still run. 79 00:04:44,000 --> 00:04:53,090 But it is a good practice that you define the name for every module that you will be using to execute 80 00:04:53,090 --> 00:04:53,810 the task. 81 00:04:54,290 --> 00:05:02,600 All right, the name will be installed Apache, and the module we will be using is the GM module. 82 00:05:02,630 --> 00:05:03,290 Great. 83 00:05:03,320 --> 00:05:11,300 Now, if you notice, as soon as you hit, enter the the shell knows that you are using YAML and it 84 00:05:11,300 --> 00:05:16,070 knows what are the indentation requirement for YAML file. 85 00:05:16,400 --> 00:05:20,540 So you don't have to use the spaces and count the spaces. 86 00:05:20,640 --> 00:05:20,800 All right. 87 00:05:20,810 --> 00:05:21,980 Anyway, coming back. 88 00:05:22,040 --> 00:05:27,220 The name of the package that you wanted installed, that is HTTP. 89 00:05:27,410 --> 00:05:28,910 Exactly the same name. 90 00:05:29,090 --> 00:05:30,590 Now, the state. 91 00:05:30,620 --> 00:05:35,240 Once you have that package, once the package is identified, what do you want it to do? 92 00:05:35,250 --> 00:05:36,890 You want it to install it. 93 00:05:36,890 --> 00:05:47,720 And for install you will use the the wording for the install is present that will tell the system that 94 00:05:47,720 --> 00:05:49,130 you want it installed. 95 00:05:49,850 --> 00:05:50,120 All right. 96 00:05:50,120 --> 00:05:51,350 So that's one task. 97 00:05:51,560 --> 00:05:58,490 The second one is I wanted to start this service, so go back to the same where our name is starting. 98 00:05:58,490 --> 00:06:04,640 So we'll put a second name for our task, which is start http dx. 99 00:06:05,270 --> 00:06:05,780 All right. 100 00:06:05,780 --> 00:06:15,830 So service, that's the module we need to use and the name for that is http dx and the state will be 101 00:06:15,830 --> 00:06:16,670 started. 102 00:06:17,360 --> 00:06:17,870 All right. 103 00:06:17,870 --> 00:06:21,590 So this is going to be once again installing it and starting this service. 104 00:06:22,190 --> 00:06:25,550 One thing you notice, please pay close attention. 105 00:06:25,790 --> 00:06:28,130 The name of the task. 106 00:06:28,130 --> 00:06:34,250 When you define the very first name, you put in a hyphen and then you put in the name. 107 00:06:34,250 --> 00:06:42,260 This is the general information that will show up and you run it when you define the the module and 108 00:06:42,260 --> 00:06:44,360 then you define the module. 109 00:06:44,510 --> 00:06:51,740 For example, in this example, you have to define the package name, then you do not use the hyphen. 110 00:06:51,740 --> 00:06:54,020 In this case, same thing here. 111 00:06:54,020 --> 00:06:55,070 The service. 112 00:06:55,280 --> 00:06:57,490 What is the name of the service you want to start? 113 00:06:57,500 --> 00:06:58,640 The name is this. 114 00:06:58,640 --> 00:07:00,650 This is these names. 115 00:07:00,650 --> 00:07:02,210 Do not use the hyphen. 116 00:07:02,240 --> 00:07:05,990 Hyphen is only used when you want to write the text. 117 00:07:06,870 --> 00:07:08,610 All right, so that is there. 118 00:07:09,300 --> 00:07:10,260 Let's save. 119 00:07:10,470 --> 00:07:13,950 And now let's run our Ansible playbook. 120 00:07:15,430 --> 00:07:22,570 And by the way, before I do that, let's check if I have a HTTP package installed on my machine or 121 00:07:22,570 --> 00:07:23,020 not. 122 00:07:23,020 --> 00:07:26,940 So for that I'll do rpm minus key and grep http pd. 123 00:07:27,650 --> 00:07:29,180 And let's see if it has it. 124 00:07:29,180 --> 00:07:29,450 Nope. 125 00:07:29,450 --> 00:07:32,810 There is no package installed on my machine. 126 00:07:32,810 --> 00:07:37,130 So now let's run the playbook. 127 00:07:42,510 --> 00:07:43,200 Okay. 128 00:07:44,330 --> 00:07:44,780 All right. 129 00:07:44,780 --> 00:07:48,330 So right here saying installing and running a partial HTP. 130 00:07:48,350 --> 00:07:49,130 This is the name. 131 00:07:49,130 --> 00:07:52,700 As I said, it's just the text is nothing else. 132 00:07:53,120 --> 00:07:57,790 Running it against local host which is right here now it's going to task install Apache. 133 00:07:57,800 --> 00:08:02,690 This is the name again this is just a text that will show up right on your screen. 134 00:08:02,810 --> 00:08:03,110 All right. 135 00:08:03,110 --> 00:08:04,490 What module you wanted to use? 136 00:08:04,490 --> 00:08:12,500 You wanted to use jump module or it says task change to local host Yes, we wanted to have it on local. 137 00:08:12,500 --> 00:08:14,690 Host The second one is also local. 138 00:08:14,690 --> 00:08:18,230 Host okay, three change. 139 00:08:18,230 --> 00:08:20,900 Two So three meaning this is. 140 00:08:20,900 --> 00:08:25,310 Host one this is one of the tasks is considering to identify which. 141 00:08:25,310 --> 00:08:27,350 Host The second one is installed. 142 00:08:27,350 --> 00:08:30,680 Apache The third one is starting the service. 143 00:08:30,680 --> 00:08:31,220 All right. 144 00:08:31,340 --> 00:08:40,370 Now, by looking at this, we know that it has worked and the playbook ran successfully. 145 00:08:40,370 --> 00:08:48,890 Now to confirm that if we have the package installed, we'll run the same command rpm grep hpdi and 146 00:08:48,890 --> 00:08:50,090 you'll see right away. 147 00:08:50,210 --> 00:08:50,900 Beautiful. 148 00:08:50,900 --> 00:08:54,650 We have all these four packages that matches hpdi. 149 00:08:54,680 --> 00:08:55,510 Excellent. 150 00:08:55,520 --> 00:08:59,570 Now the next part that we wanted to do is to start that service as well. 151 00:08:59,600 --> 00:09:06,080 So in order to check if the service is started, you'll use the command system CTL status. 152 00:09:07,130 --> 00:09:08,300 At DPD. 153 00:09:10,550 --> 00:09:11,490 Excellent. 154 00:09:11,510 --> 00:09:14,510 You'll see right here it is active loaded. 155 00:09:14,510 --> 00:09:17,600 So it is running and it is started. 156 00:09:17,600 --> 00:09:25,400 So our playbook did all of that magically instead of us running a couple of commands, which is yum 157 00:09:25,400 --> 00:09:31,720 install hdd, dpd providing minus y every time it asks whether you want to install it or not. 158 00:09:31,730 --> 00:09:38,570 Then once it's installed then we will have to go in and do system CTL start http d that will start. 159 00:09:39,080 --> 00:09:42,680 So maybe it's easier for you to do it on one machine. 160 00:09:42,680 --> 00:09:47,690 But what if you have to do the same thing on ten or 20 different machines? 161 00:09:48,610 --> 00:09:50,470 Then it's going to be cumbersome, right? 162 00:09:50,800 --> 00:09:51,460 Yes. 163 00:09:51,460 --> 00:09:54,190 That's why Ansible comes to your rescue. 164 00:09:54,340 --> 00:09:57,970 Then you have to automate these tasks for multiple. 165 00:09:58,670 --> 00:10:01,130 Machines are remote clients.