Time
2 hours 51 minutes
Difficulty
Beginner
CEU/CPE
3

Video Transcription

00:00
Hello. My name is Jasmine Jackson In our courses Intro to Vagrant And in this video I will show you a demo on how to create an external script. So let's start
00:13
Are learning objectives for this video are how to create an is an external script and vagrant So let's start our demo. So I have created a script I s h foul this scripture look familiar as we used it in less than 44
00:32
creating
00:34
on http server on our machine using secure shell. So now I have an example of I need to install Apache on multiple vagrant machines. I could use a secure shell Teoh each of machine but
00:51
that's not really optimal. So what idea? Waas
00:54
I created this script that s stage foul and what I'm going to do is I'm going to use this external script inside my vagrant files so I can use provisioning to install the software as soon as I start my vagrant machine.
01:11
So let me show you how that works.
01:15
Going back to our vagrant foul. In our last video, I shows you a demo on how to create an in line spirit which is here
01:25
so Now what we're going to do is we're going to change this in line script to turn into an external script, and the way we're going to do that is we're going to say path
01:38
script, that s H.
01:42
And the reason we can do that is because our script file is in the same directory as our vagrant file. So we're using a relative path.
01:52
If by chance my script file was in a separate location outside of my vagrant file,
01:59
then I will have to do an absolute path to specify where my script is in the operating system. But since my script file is in the same directory as my vagary file, I can just use relative paths
02:17
and this will work.
02:19
So I saved my vaguer file, and now I'm going to go
02:24
to Vagrant and I'm going to save vagrant
02:30
provision.
02:42
And as you can see,
02:44
our script worked as Apache as our Apache server is being installed.
02:52
So sorry for the output really doesn't look the best. But our Apache software has been installed again. So our external scripts works
03:07
so less clear,
03:12
and I'm going to say vagrant
03:15
at this stage,
03:16
I want to create a secure shell and to our vagrant machine,
03:24
I'm going to go to our Apache folders. So what I'm going to do is type CD for change directory, and then I'm going to type of directory.
03:38
And as you can see, we have an index that HTML file, which is our default file and if you notice it was created on December 28th which is today. So our external script was successful.
03:57
So to recap, what idea was I created a script to on America Lee install Apache. Http Server on my vagrant machine. So the example I use was I have multiple vagrant machines that I need to install
04:15
patching on. And like I said, I could
04:18
use a secure show and manually install Apache on each vagrant machine that way, but that's not optimal. So what idea was I created the scripts that I'm going to use in my vagrant foul as an external script
04:36
in the way I did that was, I specified a path
04:42
to my script file, and again, I'm using relative paths because my script file is in the same directory as my vagrant file Note. If my script foul was not in the same directory as my vaguer file. I would need to use absolute paths,
05:01
but I don't need to do that, because my spirit for I was in the same location as my vagrant file. And I could just use the relative path and the vapor foul is smart to know. Okay, let me look at my current directory. Oh, I see a script that s h file. So I'm going to execute that
05:20
next we went to Commander, which again is,
05:28
uh, council, where you can answer where you can execute linens, commands and windows. And what we did was we did the vagrant provisioned command. And you saw, even though it really wasn't
05:44
pretty. But you saw that the Apache http software was being installed so that let us know that our external script worked because as soon as we executed the provisioned command, our software started to install automatically.
06:01
And that's the beauty and power of provisioning.
06:05
Is that all I have to do is create the script once and then point the script to my vagrant files. And as soon as I as soon as I type the vagrant provisioned command and press answer the
06:23
software that I want to be installed automatically installs.
06:27
So that's the beauty. All I need to do is create the script
06:30
fire once and then point that filed to multiple vagrant files. And as soon as I execute the provision command, that script is automatically executed in that software is automatically installed.
06:46
That is very powerful, and it saves you a lot of time. And as I said in the lecture,
06:54
you know, using provisioning is automated and repeatable. So are you have to do is
07:00
create the scripts one time and that you could automate that and repeat it as many times as you want to. That's very powerful. That saves you a lot of time. You know, while the software is the stalling you could be doing other things in the background is really great. After our path she software
07:19
installed, we did a sanity check
07:23
by creating a secure shell into our machine and then
07:30
changing directories to our Apache. Http. Directory inside our boots to trustee 64 machine and we noticed that there is an index dot html file, which is the Apache default page that I showed you doing our port fording demo
07:49
and that Defar page is automatically created when you install Apache.
07:57
Because that page let's you know that your installation was successful when you see that page and we know that our external script was successful because we have a date of December 28th and today is December 28th.
08:13
So we know that our external script
08:16
executed successfully. So now let's return to our lecture. So in summary and this video, we learned how to create an external script in vagrant.
08:30
And in our next lecture, I will show you how to share your vagrant machine. We have learned a lot in this course. We downloaded a pre configured vagrant machine. We then you secure shell and installed software. We
08:48
created networks
08:50
public network, private networks using port fording.
08:54
Now we have created in line and external scripts. So now it's like, Hey, I have this great vagrant machine and now I need to share with someone. So in our next lecture, I will show you how to share your vagrant machine with
09:13
anyone. So we will create
09:16
uh, link for you to share your vagrant machine. And you know you can ship your vagrant machine to anyone that you want to. So I hope you are excited about our next lecture. And also, our next lecture will be our final lecture for this course.

Up Next

Introduction to Vagrant

In this introductory Vagrant training, students will learn Vagrant’s core concepts, how to configure the virtualization tool, and how it will benefit their organizations. Upon completion of the course, students will have a foundational understanding of Vagrant.

Instructed By

Instructor Profile Image
Jasmine Jackson
Application Security Engineer
Instructor