In this video, we are going to run multiple tasks in a playbook.
So the playbook will ping the local host as well as it will print the hello world.
So previously we ran a separate playbooks for pinging the local host and another playbook to print.
Hello world on the screen.
So what we are doing is we are combining both of those playbooks into one playbook.
So this way you will have a better understanding how you can run multiple tasks within the same playbook.
All right.
So very first thing is we have to do is we have to VI or VIM use the Vim editor to create a playbook.
And we are going to name the playbook as a task or multiple task to YAML file.
Then we will put in a dash, dash, dash to identify that it's a YAML file.
We'll give it a name running to tasks or any name of your choice.
Of course this is the name of the play.
Then the host.
Where are you going to run that tasks that will be on the local host where you have that Ansible installer,
where you're running that executable, then what are the tasks that you are running on the following
task and the name of the task.
Very first one is test connectivity of course, run ping on the local host to test his connectivity.
And what module are we going to use for that task?
You're going to use ping a module, so that's one tasks.
The second task is to print the hello world.
So if you notice that second task name is right below exactly where the first name is.
So it's going to be the name print Hello World and the module we are using.
If you remember, that's a second task.
Okay, so the module you are running for, this is the debug module.
And the message, which is the option that you will need to use is the hello world, which I'm sure
you remember, and that is to run this module.
All right.
After that, what do we do?
We run the playbook.
And you should know by now from your heart, what's the command for the playbook?
It's Ansible playbook, followed by the name of the Playbook.
Let's go to our Linux machine right here.
And I am in my playbooks directory.
And who am I?
I am logged in as root.
All right, perfect.
Now let's do a VM, multitask or task that YAML file.
All right, define that.
It's a YAML.
Put a name of the playbook or the play.
Make sure there's a space.
Don't make a mistake, otherwise we won't run it.
So running two tasks, it's just the ID.
All right, hit enter.
Host.
Where do you want it to run it on?
Right now, everything we are running on local host.
All right, let's give it a space or empty line so we look clean automatically indented.
So tasks.
What are the tasks?
You want to run it.
It will automatically advance you to the next line with the right indentation name.
And the name of the task is test connectivity.
Connectivity.
All right.
And what module you want to use for that test if you want to use ping module.
Perfect now.
What else?
I wanted to run another test.
Let's hit enter.
Automatically is indented, but we wanted to make sure this is considered as one task that has to subtasks.
So let's go back to where the name starts.
So we're going to put right below where the first name is.
So the second name of this same sub task is print hello world.
All right.
And the module that you want to run for that is the debug with its option message.
Hello World.
Double coat closed.
Take a look one more time.
Skim through it.
Make sure you have not done any mistake.
Beautiful.
It escape and colon WQ to save the file.
The file is saved.
You could do less minus l tr.
You'll see.
Right here is the file.
All right, so let's do.
And Sybil Dash playbook.
And let me clear the screen, first of all.
Now you run Ansible.
Playbook and my task, Emma.
All right.
So this is going to peg the local host where we're running the command and it is going to print Hello
World.
All right.
Ignored the first message, the warning message.
All right, here we have.
Everything looks green.
Perfect.
It's saying running to task.
This is the name.
Remember we defined right here, name running to task.
Task where we are running it.
If we're running a local host and it says, yes, okay, we are running in localhost host, that's fine.
Then the next test right here and the name of the task is test connectivity.
This is what I put it here and it says, okay, local host, meaning it pinged it.
It worked.
It has connectivity.
Good.
What is the next task name print.
Hello world.
So whatever you have it here, it will print right here.
And the debug which is the module which which actually successfully executed and the message it displayed
on the screen is hello world.
You could do a play recap right here.
Local host okay.
Three.
It ran three tasks.
It were perfectly fine.
Why three tasks?
Because first one is of course local hosts against this is to gather that facts.
Then the second one is test connectivity and the third one is the local host for running the Hello World.
That's why it tells you okay three nothing else is here.
Changed, nothing unreachable failed nothing is there.
So it means your multiple task playbook ran successfully.
Congratulations.
Now you are on the third playbook.
All ready.
I'll see you in the next one.