1 00:00:00,930 --> 00:00:05,760 All right, folks, we are getting better and better in creating Ansible playbooks. 2 00:00:06,390 --> 00:00:12,330 In this video, we are going to write another Ansible playbook which will download package from a URL. 3 00:00:12,330 --> 00:00:18,300 So the playbook name will be Tomcat YAML file, and by the name of it you could tell that we will be 4 00:00:18,300 --> 00:00:25,260 downloading Tomcat and this playbook will create a directory for Tomcat with required permissions. 5 00:00:25,860 --> 00:00:34,590 It will download Tomcat from a URL and place it in that directory, and then it will also modify the 6 00:00:34,590 --> 00:00:37,680 permission of the downloaded file. 7 00:00:38,160 --> 00:00:38,490 All right. 8 00:00:38,490 --> 00:00:44,280 So real quick, when we write the playbook, it will be Tomcat YAML. 9 00:00:44,310 --> 00:00:49,440 Then we'll define dash, dash, dash with the name download Tomcat from the location. 10 00:00:49,440 --> 00:00:55,730 And this is just the URL of the location where we were going to download it from. 11 00:00:55,740 --> 00:01:02,880 Then the host we are going to go with the local host this time the task, the first task is to create 12 00:01:02,880 --> 00:01:05,850 a directory and the directory will be slash ops, slash tomcat. 13 00:01:05,850 --> 00:01:07,950 We have to use the file module. 14 00:01:08,250 --> 00:01:10,560 These are the parameters or options. 15 00:01:10,560 --> 00:01:16,800 Then the second task is download Tomcat and we will use module get underscore URL and these are the 16 00:01:16,800 --> 00:01:17,430 options. 17 00:01:17,430 --> 00:01:21,030 Then of course, the last thing is we'll run the Tomcat YAML file. 18 00:01:21,300 --> 00:01:21,630 All right. 19 00:01:21,630 --> 00:01:26,880 So we'll go right into our ANSIBLE control node. 20 00:01:27,980 --> 00:01:31,370 And we are already in Atkins playbook. 21 00:01:31,760 --> 00:01:32,690 Who am I? 22 00:01:32,720 --> 00:01:33,930 I am logging as route. 23 00:01:33,950 --> 00:01:34,610 That's fine. 24 00:01:34,610 --> 00:01:39,470 Let's go ahead and vim tomcat dot yaml file. 25 00:01:39,620 --> 00:01:41,750 Let's define YAML. 26 00:01:42,350 --> 00:01:48,170 The name of the playbook download tomcat from. 27 00:01:49,470 --> 00:01:51,000 I'll just put it like that. 28 00:01:51,360 --> 00:01:52,470 And. 29 00:01:53,370 --> 00:02:01,050 So let's put create a directory and download Tomcat from URL. 30 00:02:03,110 --> 00:02:03,730 Okay. 31 00:02:03,740 --> 00:02:07,190 Now let's come down to hosts. 32 00:02:07,430 --> 00:02:10,640 Which host you wanted to to have a downloaded? 33 00:02:10,760 --> 00:02:16,620 Let's go ahead with our local host this time, which will download right on the control node. 34 00:02:16,640 --> 00:02:16,980 All right. 35 00:02:17,000 --> 00:02:17,810 Tasks. 36 00:02:18,720 --> 00:02:21,870 Their very first task name is. 37 00:02:23,180 --> 00:02:28,100 Create a directory, then the module. 38 00:02:28,100 --> 00:02:31,610 What module you will use for this task will use the file module. 39 00:02:31,670 --> 00:02:32,240 All right. 40 00:02:32,240 --> 00:02:34,370 Now what options? 41 00:02:34,460 --> 00:02:37,190 Parameters you will define for that module? 42 00:02:37,220 --> 00:02:45,260 First, the path where you want the file to be directory to be created as an app and the directory name 43 00:02:45,260 --> 00:02:46,430 will be Tomcat. 44 00:02:46,730 --> 00:02:52,670 The state of the directory will be directory because the file module can be used to create either file 45 00:02:52,670 --> 00:02:53,330 or a directory. 46 00:02:53,330 --> 00:03:00,650 So you have to specify if it's going to be a directory then the mod of which is the permission of that 47 00:03:00,650 --> 00:03:01,520 directory. 48 00:03:01,610 --> 00:03:06,530 0755 this you could change it with change mod as well. 49 00:03:07,250 --> 00:03:10,520 Owner who is going to be the owner of this directory. 50 00:03:10,520 --> 00:03:11,330 Let's put it down. 51 00:03:11,330 --> 00:03:13,280 Root group. 52 00:03:13,640 --> 00:03:15,080 Let's do it root as well. 53 00:03:15,090 --> 00:03:19,420 You could change it to any other user like Tomcat user as well. 54 00:03:19,430 --> 00:03:28,640 But if you are creating owner as Tomcat or group Tomcat, then make sure that user exists in your Linux 55 00:03:28,640 --> 00:03:29,030 machine. 56 00:03:29,030 --> 00:03:29,510 All right. 57 00:03:29,510 --> 00:03:30,830 That's one task. 58 00:03:31,070 --> 00:03:39,770 The second task name is download Tomcat using. 59 00:03:43,380 --> 00:03:45,490 Download Tomcat from URL. 60 00:03:45,510 --> 00:03:46,560 Just simple as that. 61 00:03:47,010 --> 00:03:52,380 All right, now we will use get underscore URL. 62 00:03:52,560 --> 00:03:54,000 That's the module. 63 00:03:54,630 --> 00:03:55,290 All right. 64 00:03:55,290 --> 00:04:03,210 And the URL will be let's save this file for now because I have already copied the URL. 65 00:04:04,430 --> 00:04:06,140 In Cat. 66 00:04:07,260 --> 00:04:08,010 Temp. 67 00:04:08,990 --> 00:04:10,270 File location. 68 00:04:10,280 --> 00:04:15,440 This is the location of the file where I have copied the entire location. 69 00:04:15,770 --> 00:04:17,740 Edit Copy. 70 00:04:17,750 --> 00:04:26,990 All right, now let's go to let's go back to our Tomcat file and then simply paste it right here. 71 00:04:26,990 --> 00:04:27,560 Edit. 72 00:04:28,260 --> 00:04:35,400 Paste now make sure if you have the right URL, don't go with the URL that I have. 73 00:04:35,430 --> 00:04:39,360 Always go with the URL that is available right now. 74 00:04:39,390 --> 00:04:47,410 You could do that by going to I have that copied right here in my notepad as well as copy. 75 00:04:47,430 --> 00:04:56,940 Let's go to Firefox and let's just simply type right here and you'll see right here. 76 00:04:56,940 --> 00:04:58,860 It says downloaded, completed. 77 00:04:58,860 --> 00:05:01,590 So it means this URL is good. 78 00:05:01,590 --> 00:05:10,620 If you do not have the correct URL, then I would say do download tomcat and go to the software. 79 00:05:10,620 --> 00:05:18,270 Pick which target g zip file, then right click and do copy link. 80 00:05:18,630 --> 00:05:20,760 That's how you could get the exact location. 81 00:05:20,760 --> 00:05:22,020 All right, let's close this. 82 00:05:23,520 --> 00:05:24,600 Let's minimize this. 83 00:05:24,600 --> 00:05:26,550 Let's go back to our control node. 84 00:05:26,880 --> 00:05:31,260 And here we have our URL defined. 85 00:05:31,260 --> 00:05:33,510 Now, the destination. 86 00:05:34,140 --> 00:05:37,500 Where do you want this file to be downloaded? 87 00:05:37,500 --> 00:05:44,010 We want it to be downloaded to Tomcat Directory, which we created in the earlier task. 88 00:05:44,250 --> 00:05:44,610 All right. 89 00:05:44,610 --> 00:05:46,200 Do you want to give it a different permission? 90 00:05:46,200 --> 00:05:46,560 Yes. 91 00:05:46,560 --> 00:05:48,270 0755. 92 00:05:48,360 --> 00:05:51,360 Then do you want to give give a different ownership? 93 00:05:51,360 --> 00:05:52,020 Yes. 94 00:05:52,020 --> 00:05:58,080 You could give a different owner of your choice group will be your future choice. 95 00:05:58,230 --> 00:06:02,070 Of course, putting down a group or owner first doesn't really matter. 96 00:06:02,550 --> 00:06:04,380 All right, let's save the file. 97 00:06:05,340 --> 00:06:08,070 And now, moment of truth. 98 00:06:08,070 --> 00:06:10,410 Let's run the Ansible playbook. 99 00:06:10,780 --> 00:06:20,310 Ansible, before we run it, let's make sure we do not have any Tomcat directory in our opt. 100 00:06:21,440 --> 00:06:22,250 Directory. 101 00:06:22,640 --> 00:06:24,170 Here we have it. 102 00:06:24,290 --> 00:06:26,960 There is nothing in slash opt. 103 00:06:26,990 --> 00:06:27,840 Okay, good. 104 00:06:27,860 --> 00:06:32,960 Now let's go back to our Etsy and symbol and playbooks. 105 00:06:33,710 --> 00:06:40,610 All right, now let's run our Ansible playbook, tomcat. 106 00:06:42,080 --> 00:06:43,130 YAML file. 107 00:06:43,820 --> 00:06:44,360 All right. 108 00:06:44,360 --> 00:06:47,740 The first thing it will do is create a directory and download Tomcat. 109 00:06:47,750 --> 00:06:55,180 This is the name, it's showing local host and the task is to create a directory done and download Tomcat 110 00:06:55,190 --> 00:06:55,730 changed. 111 00:06:55,730 --> 00:06:56,970 Dun dun dun. 112 00:06:57,050 --> 00:06:59,330 We have no error messages. 113 00:06:59,360 --> 00:07:00,170 Excellent. 114 00:07:00,170 --> 00:07:03,610 It means our playbook ran successfully. 115 00:07:03,620 --> 00:07:08,000 Now that's where we got that information from this output. 116 00:07:08,000 --> 00:07:09,920 But we always have to verify. 117 00:07:09,920 --> 00:07:16,580 But actually going into first checking to see if the directory is created in slash OPPT. 118 00:07:17,150 --> 00:07:19,280 All right, let's go to CD Slash OPPT. 119 00:07:19,430 --> 00:07:26,360 Now let's do less minus L and you'll see here is the directory that's been created. 120 00:07:26,390 --> 00:07:29,420 It is owned by root because we define root here. 121 00:07:29,420 --> 00:07:38,180 It has the right permission which is read, write X for user and executable and read for others. 122 00:07:38,510 --> 00:07:38,870 All right. 123 00:07:38,870 --> 00:07:46,910 So now let's go into the Tomcat directory and see if it has downloaded the Tom Cat G zip file. 124 00:07:47,030 --> 00:07:52,970 Let's do CD and do LS minus LTR or less minus l hit enter. 125 00:07:52,970 --> 00:07:59,200 And right here is your dot file that we downloaded from this URL. 126 00:07:59,210 --> 00:08:07,070 Now as you notice it is owned by Afzal Group is owned by Absol and it has the right permission. 127 00:08:07,400 --> 00:08:08,030 All right. 128 00:08:08,030 --> 00:08:16,850 So now, you know, you learn another module of getting a URL and if you want to download it and using 129 00:08:17,630 --> 00:08:18,560 your URL. 130 00:08:18,560 --> 00:08:23,420 Now, if you have to download it, of course, if you remember, if you download it without the Ansible 131 00:08:23,420 --> 00:08:26,750 playbook, then you will use wget command. 132 00:08:26,750 --> 00:08:33,830 But if you are downloading the same package into multiple Linux systems, then of course Ansible playbook 133 00:08:33,830 --> 00:08:36,050 would be the best option. 134 00:08:36,680 --> 00:08:45,050 Another thing make sure you have internet access on your Linux machine where you're running this YAML 135 00:08:45,050 --> 00:08:46,070 file against.