1 00:00:00,960 --> 00:00:06,030 In this video, we are going to run multiple tasks in a playbook. 2 00:00:06,030 --> 00:00:13,890 So the playbook will ping the local host as well as it will print the hello world. 3 00:00:13,920 --> 00:00:22,350 So previously we ran a separate playbooks for pinging the local host and another playbook to print. 4 00:00:22,380 --> 00:00:24,030 Hello world on the screen. 5 00:00:24,030 --> 00:00:29,940 So what we are doing is we are combining both of those playbooks into one playbook. 6 00:00:29,940 --> 00:00:36,870 So this way you will have a better understanding how you can run multiple tasks within the same playbook. 7 00:00:37,320 --> 00:00:37,710 All right. 8 00:00:37,710 --> 00:00:46,200 So very first thing is we have to do is we have to VI or VIM use the Vim editor to create a playbook. 9 00:00:46,200 --> 00:00:52,440 And we are going to name the playbook as a task or multiple task to YAML file. 10 00:00:53,220 --> 00:00:57,930 Then we will put in a dash, dash, dash to identify that it's a YAML file. 11 00:00:57,930 --> 00:01:02,010 We'll give it a name running to tasks or any name of your choice. 12 00:01:02,010 --> 00:01:04,680 Of course this is the name of the play. 13 00:01:05,160 --> 00:01:06,060 Then the host. 14 00:01:06,150 --> 00:01:14,850 Where are you going to run that tasks that will be on the local host where you have that Ansible installer, 15 00:01:14,850 --> 00:01:21,210 where you're running that executable, then what are the tasks that you are running on the following 16 00:01:21,210 --> 00:01:23,670 task and the name of the task. 17 00:01:23,670 --> 00:01:31,590 Very first one is test connectivity of course, run ping on the local host to test his connectivity. 18 00:01:31,590 --> 00:01:35,940 And what module are we going to use for that task? 19 00:01:35,940 --> 00:01:41,310 You're going to use ping a module, so that's one tasks. 20 00:01:41,580 --> 00:01:44,160 The second task is to print the hello world. 21 00:01:44,160 --> 00:01:50,850 So if you notice that second task name is right below exactly where the first name is. 22 00:01:50,850 --> 00:01:55,500 So it's going to be the name print Hello World and the module we are using. 23 00:01:55,500 --> 00:01:58,620 If you remember, that's a second task. 24 00:01:58,620 --> 00:02:02,880 Okay, so the module you are running for, this is the debug module. 25 00:02:02,880 --> 00:02:07,800 And the message, which is the option that you will need to use is the hello world, which I'm sure 26 00:02:07,800 --> 00:02:11,820 you remember, and that is to run this module. 27 00:02:12,450 --> 00:02:13,020 All right. 28 00:02:13,020 --> 00:02:14,280 After that, what do we do? 29 00:02:14,310 --> 00:02:15,450 We run the playbook. 30 00:02:15,450 --> 00:02:20,130 And you should know by now from your heart, what's the command for the playbook? 31 00:02:20,130 --> 00:02:23,430 It's Ansible playbook, followed by the name of the Playbook. 32 00:02:24,060 --> 00:02:27,330 Let's go to our Linux machine right here. 33 00:02:27,480 --> 00:02:32,910 And I am in my playbooks directory. 34 00:02:33,210 --> 00:02:36,060 And who am I? 35 00:02:36,090 --> 00:02:38,460 I am logged in as root. 36 00:02:38,460 --> 00:02:39,570 All right, perfect. 37 00:02:39,570 --> 00:02:45,600 Now let's do a VM, multitask or task that YAML file. 38 00:02:46,170 --> 00:02:48,000 All right, define that. 39 00:02:48,000 --> 00:02:49,110 It's a YAML. 40 00:02:49,140 --> 00:02:51,660 Put a name of the playbook or the play. 41 00:02:51,660 --> 00:02:52,800 Make sure there's a space. 42 00:02:52,800 --> 00:02:55,470 Don't make a mistake, otherwise we won't run it. 43 00:02:55,950 --> 00:02:59,760 So running two tasks, it's just the ID. 44 00:03:00,240 --> 00:03:02,040 All right, hit enter. 45 00:03:02,040 --> 00:03:02,670 Host. 46 00:03:02,670 --> 00:03:05,400 Where do you want it to run it on? 47 00:03:05,400 --> 00:03:09,240 Right now, everything we are running on local host. 48 00:03:09,840 --> 00:03:16,410 All right, let's give it a space or empty line so we look clean automatically indented. 49 00:03:16,410 --> 00:03:17,580 So tasks. 50 00:03:17,580 --> 00:03:18,660 What are the tasks? 51 00:03:18,660 --> 00:03:20,040 You want to run it. 52 00:03:20,430 --> 00:03:27,210 It will automatically advance you to the next line with the right indentation name. 53 00:03:27,780 --> 00:03:31,320 And the name of the task is test connectivity. 54 00:03:32,100 --> 00:03:33,540 Connectivity. 55 00:03:33,550 --> 00:03:34,350 All right. 56 00:03:34,350 --> 00:03:38,040 And what module you want to use for that test if you want to use ping module. 57 00:03:38,960 --> 00:03:40,190 Perfect now. 58 00:03:40,730 --> 00:03:41,510 What else? 59 00:03:41,540 --> 00:03:43,370 I wanted to run another test. 60 00:03:43,410 --> 00:03:44,420 Let's hit enter. 61 00:03:44,750 --> 00:03:54,470 Automatically is indented, but we wanted to make sure this is considered as one task that has to subtasks. 62 00:03:54,470 --> 00:03:58,050 So let's go back to where the name starts. 63 00:03:58,050 --> 00:04:02,000 So we're going to put right below where the first name is. 64 00:04:02,000 --> 00:04:10,970 So the second name of this same sub task is print hello world. 65 00:04:11,150 --> 00:04:12,110 All right. 66 00:04:12,110 --> 00:04:18,560 And the module that you want to run for that is the debug with its option message. 67 00:04:20,290 --> 00:04:21,480 Hello World. 68 00:04:25,200 --> 00:04:26,580 Double coat closed. 69 00:04:27,090 --> 00:04:28,740 Take a look one more time. 70 00:04:28,740 --> 00:04:29,400 Skim through it. 71 00:04:29,400 --> 00:04:31,570 Make sure you have not done any mistake. 72 00:04:31,590 --> 00:04:32,310 Beautiful. 73 00:04:32,310 --> 00:04:37,530 It escape and colon WQ to save the file. 74 00:04:37,530 --> 00:04:38,550 The file is saved. 75 00:04:38,550 --> 00:04:40,110 You could do less minus l tr. 76 00:04:40,110 --> 00:04:40,950 You'll see. 77 00:04:40,950 --> 00:04:43,140 Right here is the file. 78 00:04:43,590 --> 00:04:45,300 All right, so let's do. 79 00:04:46,720 --> 00:04:50,230 And Sybil Dash playbook. 80 00:04:50,620 --> 00:04:54,370 And let me clear the screen, first of all. 81 00:04:54,640 --> 00:04:56,380 Now you run Ansible. 82 00:04:57,830 --> 00:05:01,910 Playbook and my task, Emma. 83 00:05:01,940 --> 00:05:02,330 All right. 84 00:05:02,330 --> 00:05:08,750 So this is going to peg the local host where we're running the command and it is going to print Hello 85 00:05:08,750 --> 00:05:09,200 World. 86 00:05:10,110 --> 00:05:11,070 All right. 87 00:05:11,280 --> 00:05:14,520 Ignored the first message, the warning message. 88 00:05:14,610 --> 00:05:15,870 All right, here we have. 89 00:05:15,870 --> 00:05:17,320 Everything looks green. 90 00:05:17,340 --> 00:05:18,270 Perfect. 91 00:05:18,720 --> 00:05:20,390 It's saying running to task. 92 00:05:20,400 --> 00:05:21,360 This is the name. 93 00:05:21,360 --> 00:05:25,200 Remember we defined right here, name running to task. 94 00:05:25,440 --> 00:05:27,270 Task where we are running it. 95 00:05:27,270 --> 00:05:32,270 If we're running a local host and it says, yes, okay, we are running in localhost host, that's fine. 96 00:05:32,280 --> 00:05:37,230 Then the next test right here and the name of the task is test connectivity. 97 00:05:37,230 --> 00:05:42,780 This is what I put it here and it says, okay, local host, meaning it pinged it. 98 00:05:42,780 --> 00:05:43,440 It worked. 99 00:05:43,440 --> 00:05:44,760 It has connectivity. 100 00:05:45,030 --> 00:05:45,450 Good. 101 00:05:45,450 --> 00:05:48,240 What is the next task name print. 102 00:05:48,240 --> 00:05:48,870 Hello world. 103 00:05:48,870 --> 00:05:53,880 So whatever you have it here, it will print right here. 104 00:05:53,880 --> 00:06:03,420 And the debug which is the module which which actually successfully executed and the message it displayed 105 00:06:03,420 --> 00:06:05,520 on the screen is hello world. 106 00:06:06,570 --> 00:06:08,490 You could do a play recap right here. 107 00:06:08,490 --> 00:06:09,720 Local host okay. 108 00:06:09,720 --> 00:06:10,140 Three. 109 00:06:10,170 --> 00:06:11,550 It ran three tasks. 110 00:06:11,550 --> 00:06:13,230 It were perfectly fine. 111 00:06:13,230 --> 00:06:14,070 Why three tasks? 112 00:06:14,070 --> 00:06:19,440 Because first one is of course local hosts against this is to gather that facts. 113 00:06:19,440 --> 00:06:25,860 Then the second one is test connectivity and the third one is the local host for running the Hello World. 114 00:06:25,860 --> 00:06:29,310 That's why it tells you okay three nothing else is here. 115 00:06:29,310 --> 00:06:32,760 Changed, nothing unreachable failed nothing is there. 116 00:06:32,760 --> 00:06:36,900 So it means your multiple task playbook ran successfully. 117 00:06:36,900 --> 00:06:37,890 Congratulations. 118 00:06:37,890 --> 00:06:39,750 Now you are on the third playbook. 119 00:06:39,750 --> 00:06:40,590 All ready. 120 00:06:40,830 --> 00:06:42,660 I'll see you in the next one.