All right, folks, we are getting better and better in creating Ansible playbooks.
In this video, we are going to write another Ansible playbook which will download package from a URL.
So the playbook name will be Tomcat YAML file, and by the name of it you could tell that we will be
downloading Tomcat and this playbook will create a directory for Tomcat with required permissions.
It will download Tomcat from a URL and place it in that directory, and then it will also modify the
permission of the downloaded file.
All right.
So real quick, when we write the playbook, it will be Tomcat YAML.
Then we'll define dash, dash, dash with the name download Tomcat from the location.
And this is just the URL of the location where we were going to download it from.
Then the host we are going to go with the local host this time the task, the first task is to create
a directory and the directory will be slash ops, slash tomcat.
We have to use the file module.
These are the parameters or options.
Then the second task is download Tomcat and we will use module get underscore URL and these are the
options.
Then of course, the last thing is we'll run the Tomcat YAML file.
All right.
So we'll go right into our ANSIBLE control node.
And we are already in Atkins playbook.
Who am I?
I am logging as route.
That's fine.
Let's go ahead and vim tomcat dot yaml file.
Let's define YAML.
The name of the playbook download tomcat from.
I'll just put it like that.
And.
So let's put create a directory and download Tomcat from URL.
Okay.
Now let's come down to hosts.
Which host you wanted to to have a downloaded?
Let's go ahead with our local host this time, which will download right on the control node.
All right.
Tasks.
Their very first task name is.
Create a directory, then the module.
What module you will use for this task will use the file module.
All right.
Now what options?
Parameters you will define for that module?
First, the path where you want the file to be directory to be created as an app and the directory name
will be Tomcat.
The state of the directory will be directory because the file module can be used to create either file
or a directory.
So you have to specify if it's going to be a directory then the mod of which is the permission of that
directory.
0755 this you could change it with change mod as well.
Owner who is going to be the owner of this directory.
Let's put it down.
Root group.
Let's do it root as well.
You could change it to any other user like Tomcat user as well.
But if you are creating owner as Tomcat or group Tomcat, then make sure that user exists in your Linux
machine.
All right.
That's one task.
The second task name is download Tomcat using.
Download Tomcat from URL.
Just simple as that.
All right, now we will use get underscore URL.
That's the module.
All right.
And the URL will be let's save this file for now because I have already copied the URL.
In Cat.
Temp.
File location.
This is the location of the file where I have copied the entire location.
Edit Copy.
All right, now let's go to let's go back to our Tomcat file and then simply paste it right here.
Edit.
Paste now make sure if you have the right URL, don't go with the URL that I have.
Always go with the URL that is available right now.
You could do that by going to I have that copied right here in my notepad as well as copy.
Let's go to Firefox and let's just simply type right here and you'll see right here.
It says downloaded, completed.
So it means this URL is good.
If you do not have the correct URL, then I would say do download tomcat and go to the software.
Pick which target g zip file, then right click and do copy link.
That's how you could get the exact location.
All right, let's close this.
Let's minimize this.
Let's go back to our control node.
And here we have our URL defined.
Now, the destination.
Where do you want this file to be downloaded?
We want it to be downloaded to Tomcat Directory, which we created in the earlier task.
All right.
Do you want to give it a different permission?
Yes.
0755.
Then do you want to give give a different ownership?
Yes.
You could give a different owner of your choice group will be your future choice.
Of course, putting down a group or owner first doesn't really matter.
All right, let's save the file.
And now, moment of truth.
Let's run the Ansible playbook.
Ansible, before we run it, let's make sure we do not have any Tomcat directory in our opt.
Directory.
Here we have it.
There is nothing in slash opt.
Okay, good.
Now let's go back to our Etsy and symbol and playbooks.
All right, now let's run our Ansible playbook, tomcat.
YAML file.
All right.
The first thing it will do is create a directory and download Tomcat.
This is the name, it's showing local host and the task is to create a directory done and download Tomcat
changed.
Dun dun dun.
We have no error messages.
Excellent.
It means our playbook ran successfully.
Now that's where we got that information from this output.
But we always have to verify.
But actually going into first checking to see if the directory is created in slash OPPT.
All right, let's go to CD Slash OPPT.
Now let's do less minus L and you'll see here is the directory that's been created.
It is owned by root because we define root here.
It has the right permission which is read, write X for user and executable and read for others.
All right.
So now let's go into the Tomcat directory and see if it has downloaded the Tom Cat G zip file.
Let's do CD and do LS minus LTR or less minus l hit enter.
And right here is your dot file that we downloaded from this URL.
Now as you notice it is owned by Afzal Group is owned by Absol and it has the right permission.
All right.
So now, you know, you learn another module of getting a URL and if you want to download it and using
your URL.
Now, if you have to download it, of course, if you remember, if you download it without the Ansible
playbook, then you will use wget command.
But if you are downloading the same package into multiple Linux systems, then of course Ansible playbook
would be the best option.
Another thing make sure you have internet access on your Linux machine where you're running this YAML
file against.