Hey, folks, welcome back.
In this video, we will be installing and starting up a package in a Linux machine.
So the very first thing is we'll pick a name for the YAML file, which we are creating for our playbook.
Then defining the dash, dash, dash, which tells us that this is going to be a YAML file.
Now the name of the playbook installing and running Apache or installing and running HTTP de.
That's the name of the package of the Apache.
All right, the host, where do you want to install and run this Apache package?
You want to run it on a local host.
All right.
The tasks the third thing, what exactly we're doing, the name is that at this time, we will install
Apache or HTTP.
All right.
Tell me the module that you will use to do that installation.
We'll use the Yum module.
All right.
Or you could use DNF.
All right.
The name of the package will be a HTTP feed.
Now, this is the exact name that you will use as if you are running yum install followed by the package
name or DNF install followed by HTTP.
This has to match with that package.
All right.
So once we have it, what do you want it to do with this?
So we know you want to the name is a general information you want to install package and we will be
using Yum command.
But we could also do remove using Yum command and we could also do a lot a lot of other functions with
Yum.
So what exactly wanted to do with this package?
We wanted to use the state as present, which tells the Ansible executables that we wanted it to be
installed.
So the package name is HTTP PD.
And when you put in the state and and you define the state as present, it means that we want the package
to be installed.
Beautiful.
Now the next thing is package is installed.
Now we want to start the package, the service of the package to be started.
For that, we have to give it a new name for that task and that is start http dx.
Now if you notice, that name is exactly under the same vertical column of the name of the first name
where we have the install package.
All right.
Then the module that we will be using to start the service is the service module and the name for what
package.
For that service we want to install is start.
That is http.
All right.
Now, the state the state here is different than installing it and that is started.
These are the few things that you have to remember if you do not remember these options and you could
go back to the documentation and go to the module for Yum!
Or go to the module for service.
And then you could see what are the options that are available to you and whether you should use the
state started or stop or present where you should use it and where you should not.
All right.
That's about it.
This entire playbook is going to be installing the HTTP package and starting up its service.
Now, once this playbook is completed and saved, then we'll go ahead and run the pack, install the
YAML file.
All right, so let's go to our Linux machine right here and let's log in as root.
All right.
So we are in our home directory, which is at Ansible Playbooks, which is the directory we are using
to keep all of our playbooks.
Who am I?
I am logged in as root.
All right, perfect.
Now let's go ahead and create the YAML file and we are naming it pack install or ensure package install
yaml.
Hit enter.
Now define dash.
Dash.
Dash name.
Installing and running.
Apache or http.
DD That's fine.
Now, where do you want it to run?
We want it to run it on local hosts.
All right.
The tasks, what you want it to do, you want it to, first of all, give it a name of the task.
By the way, if you don't give a name for a task that is still fine, the Ansible would still run.
But it is a good practice that you define the name for every module that you will be using to execute
the task.
All right, the name will be installed Apache, and the module we will be using is the GM module.
Great.
Now, if you notice, as soon as you hit, enter the the shell knows that you are using YAML and it
knows what are the indentation requirement for YAML file.
So you don't have to use the spaces and count the spaces.
All right.
Anyway, coming back.
The name of the package that you wanted installed, that is HTTP.
Exactly the same name.
Now, the state.
Once you have that package, once the package is identified, what do you want it to do?
You want it to install it.
And for install you will use the the wording for the install is present that will tell the system that
you want it installed.
All right.
So that's one task.
The second one is I wanted to start this service, so go back to the same where our name is starting.
So we'll put a second name for our task, which is start http dx.
All right.
So service, that's the module we need to use and the name for that is http dx and the state will be
started.
All right.
So this is going to be once again installing it and starting this service.
One thing you notice, please pay close attention.
The name of the task.
When you define the very first name, you put in a hyphen and then you put in the name.
This is the general information that will show up and you run it when you define the the module and
then you define the module.
For example, in this example, you have to define the package name, then you do not use the hyphen.
In this case, same thing here.
The service.
What is the name of the service you want to start?
The name is this.
This is these names.
Do not use the hyphen.
Hyphen is only used when you want to write the text.
All right, so that is there.
Let's save.
And now let's run our Ansible playbook.
And by the way, before I do that, let's check if I have a HTTP package installed on my machine or
not.
So for that I'll do rpm minus key and grep http pd.
And let's see if it has it.
Nope.
There is no package installed on my machine.
So now let's run the playbook.
Okay.
All right.
So right here saying installing and running a partial HTP.
This is the name.
As I said, it's just the text is nothing else.
Running it against local host which is right here now it's going to task install Apache.
This is the name again this is just a text that will show up right on your screen.
All right.
What module you wanted to use?
You wanted to use jump module or it says task change to local host Yes, we wanted to have it on local.
Host The second one is also local.
Host okay, three change.
Two So three meaning this is.
Host one this is one of the tasks is considering to identify which.
Host The second one is installed.
Apache The third one is starting the service.
All right.
Now, by looking at this, we know that it has worked and the playbook ran successfully.
Now to confirm that if we have the package installed, we'll run the same command rpm grep hpdi and
you'll see right away.
Beautiful.
We have all these four packages that matches hpdi.
Excellent.
Now the next part that we wanted to do is to start that service as well.
So in order to check if the service is started, you'll use the command system CTL status.
At DPD.
Excellent.
You'll see right here it is active loaded.
So it is running and it is started.
So our playbook did all of that magically instead of us running a couple of commands, which is yum
install hdd, dpd providing minus y every time it asks whether you want to install it or not.
Then once it's installed then we will have to go in and do system CTL start http d that will start.
So maybe it's easier for you to do it on one machine.
But what if you have to do the same thing on ten or 20 different machines?
Then it's going to be cumbersome, right?
Yes.
That's why Ansible comes to your rescue.
Then you have to automate these tasks for multiple.
Machines are remote clients.