0% found this document useful (0 votes)
20 views27 pages

4 Vagrant

Vagrant is a tool designed for building and managing virtual machine environments, streamlining the setup process for developers, operators, and designers alike. It integrates with hypervisors and uses Vagrantfiles to automate the configuration of virtual machines, ensuring consistency across different environments. The document also covers installation instructions, creating Vagrantfiles, and managing virtual machines through commands like 'vagrant up' and 'vagrant ssh'.

Uploaded by

Aslam Ansari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views27 pages

4 Vagrant

Vagrant is a tool designed for building and managing virtual machine environments, streamlining the setup process for developers, operators, and designers alike. It integrates with hypervisors and uses Vagrantfiles to automate the configuration of virtual machines, ensuring consistency across different environments. The document also covers installation instructions, creating Vagrantfiles, and managing virtual machines through commands like 'vagrant up' and 'vagrant ssh'.

Uploaded by

Aslam Ansari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 27

IV.

Introduction to Vagrant
Vagrant is a tool for building and managing virtual machine environments in a single workflow.
With an easy-to-use workflow and focus on automation, Vagrant lowers development environment
setup time, increases productivity.

1. Why Vagrant?
If I put it in a single sentence, there is no such tool as vagrant for managing virtual machine
lifecycle. Vagrant gets integrated with hypervisors like VirtualBox and gives as a command line
interface to automate vm lifecycle.
Then, industry-standard provisioning tools such as shell scripts, Ansible, Chef, or Puppet, can
automatically install and configure software on the virtual machine.
As per Vagrant Documentation.

For Developers
If you are a developer, Vagrant will isolate dependencies and their configuration within a single
disposable, consistent environment, without sacrificing any of the tools you are used to working
with (editors, browsers, debuggers, etc.). Once you or someone else creates a single Vagrantfile,
you just need to vagrant up and everything is installed and configured for you to work. Other
members of your team create their development environments from the same configuration, so
whether you are working on Linux, Mac OS X, or Windows, all your team members are running
code in the same environment, against the same dependencies, all configured the same way. Say
goodbye to "works on my machine" bugs.

For Operators
If you are an operations engineer or DevOps engineer, Vagrant gives you a disposable
environment and consistent workflow for developing and testing infrastructure management scripts.
You can quickly test things like shell scripts, Chef cookbooks, Puppet modules, and more using
local virtualization such as VirtualBox or VMware. Then, with the same configuration, you can test
these scripts on remote clouds such as AWS or RackSpace with the same workflow. Ditch your
custom scripts to recycle EC2 instances, stop juggling SSH prompts to various machines, and start
using Vagrant to bring sanity to your life.

For Designers
If you are a designer, Vagrant will automatically set everything up that is required for that web app
in order for you to focus on doing what you do best: design. Once a developer configures Vagrant,
you do not need to worry about how to get that app running ever again. No more bothering other
developers to help you fix your environment so you can test designs. Just check out the code,
vagrant up, and start designing.

For Everyone
Vagrant is designed for everyone as the easiest and fastest way to create a virtualized environment!

Visualpath Training & Consulting.


Flat no: 205, Nilgiri Block,Aditya Enclave, Ameerpet, Hyderabad, Phone No: - +91-970 445 5959, 961 824 5689 E-
Mail ID : [email protected], Website : www.visualpath.in.
2. Installing Vagrant on windows.
Download Vagrant.

 Go to Vagrant Download page, Click Windows Installer.

 Open vagrant msi file and follow the installation wizard.

Visualpath Training & Consulting.


Flat no: 205, Nilgiri Block,Aditya Enclave, Ameerpet, Hyderabad, Phone No: - +91-970 445 5959, 961 824 5689 E-
Mail ID : [email protected], Website : www.visualpath.in.
3.Git Bash CLI
As stated earlier vagrant is a command line tool and windows command prompt is just sluggish to
run vagrant commands. So, we will need a better command line utility, one of them is Git bash.

Download git for windows.

 Go to git scm download page, Select windows.

 Open git installable and follow the Installation wizard, take all the default settings in the
wizard.

4.Vagrant Cloud.

The biggest USP of vagrant is the vagrant cloud. There is no OS installation procedures when we
use vagrant. Vagrant solves that problem by giving us vagrant boxes.

Vagrant boxes are VM images which already has the OS and softwares installed in them. We just
need to download these boxes from vagrant cloud by using our vagrant CLI. Once the box is
downloaded you can create as many as VM’s from them.

https://atlas.hashicorp.com/boxes/search?utm_source=vagrantcloud.com&vagrantcloud=1

Visualpath Training & Consulting.


Flat no: 205, Nilgiri Block,Aditya Enclave, Ameerpet, Hyderabad, Phone No: - +91-970 445 5959, 961 824 5689 E-
Mail ID : [email protected], Website : www.visualpath.in.
Majority of the boxes are of VirtualBox but there are many other boxes that supports other
hypervisors like Vmware workstation, livirt, hyperv etc.

In the next exercise, we will setup an Ubuntu and Centos VM with vagrant.

5. Vagrantfile
The first step of setting up VM with vagrant is to create Vagrantfile. Vagrantfile has all the
information about the virtual machine, which vagrant will read and configure vm for us.
The primary function of the Vagrantfile is to describe the type of machine required for a project,
and how to configure and provision these machines. Vagrantfiles are called Vagrantfiles because
the actual literal filename for the file is Vagrantfile.

The syntax of Vagrantfiles is Ruby, but knowledge of the Ruby programming language is not
necessary to make modifications to the Vagrantfile, since it is mostly simple variable assignment. In
fact, Ruby is not even the most popular community Vagrant is used within, which should help show
you that despite not having Ruby knowledge, people are very successful with Vagrant.

Visualpath Training & Consulting.


Flat no: 205, Nilgiri Block,Aditya Enclave, Ameerpet, Hyderabad, Phone No: - +91-970 445 5959, 961 824 5689 E-
Mail ID : [email protected], Website : www.visualpath.in.
6. Creating Centos & Ubuntu VM’s using Vagrant tool.

 Go to C drive => Create folder named vagrant-vm

 Go to C:\vagrant-vms => Create two folders named centos-vm & ubuntu-vm

 Open git bash.

Visualpath Training & Consulting.


Flat no: 205, Nilgiri Block,Aditya Enclave, Ameerpet, Hyderabad, Phone No: - +91-970 445 5959, 961 824 5689 E-
Mail ID : [email protected], Website : www.visualpath.in.
7. Creating a Vagrantfile
Vagrant init command creates a sample vagrant file. We can create a Vagrantfile manually
also and put all the configuration of the vm. But just to keep it simple initially we will use
vagrant init command.
1) cd /c/vagrant-vms/centos-vm
2) vagrant init nrel/Centos-6.5-x86_64
3) ls

 Go to centos-vm folder and check the file => Open it with Notepad++ editor.

Visualpath Training & Consulting.


Flat no: 205, Nilgiri Block,Aditya Enclave, Ameerpet, Hyderabad, Phone No: - +91-970 445 5959, 961 824 5689 E-
Mail ID : [email protected], Website : www.visualpath.in.
8. First look at a Vagrantfile.
As we have hit vagrant init <boxname> command, it created a sample Vagrantfile and placed box
name as shown in the screenshot. Box name should match with the name of box in the vagrant
cloud, as it is going to download the box from vagrant cloud.

 Close notepad++ after verification & Open git bash again.

9. Vagrant up
 Go to centos-vm folder from git bash and run “vagrant up” command.
Vagrant up commands read the configuration from the Vagrantfile.

This is the single most important command in Vagrant, since it is how any Vagrant machine
is created. Anyone using Vagrant must use this command on a day-to-day basis.
As we just specified the boxname its going to take other settings as defaults. Default settings
include RAM size, CPU, hard disk, network etc.

Visualpath Training & Consulting.


Flat no: 205, Nilgiri Block,Aditya Enclave, Ameerpet, Hyderabad, Phone No: - +91-970 445 5959, 961 824 5689 E-
Mail ID : [email protected], Website : www.visualpath.in.
Visualpath Training & Consulting.
Flat no: 205, Nilgiri Block,Aditya Enclave, Ameerpet, Hyderabad, Phone No: - +91-970 445 5959, 961 824 5689 E-
Mail ID : [email protected], Website : www.visualpath.in.
10. Vagrant ssh
This will SSH into a running Vagrant machine and give you access to a shell.

 Once the vm is up login to the vm by giving “vagrant ssh” command.

 Follow the same procedure in ubuntu-vm folder, Open another git bash prompt.
1) cd /c/vagrant-vms/ubuntu-vm
2) vagrant init ubuntu/trusty64
3) vagrant up

Visualpath Training & Consulting.


Flat no: 205, Nilgiri Block,Aditya Enclave, Ameerpet, Hyderabad, Phone No: - +91-970 445 5959, 961 824 5689 E-
Mail ID : [email protected], Website : www.visualpath.in.
11.Verification.
We are using the default hypervisor for vagrant which is Virtualbox. We will open up our
virtualbox interface and check our running VM which we just created. This is not a required step
but just to show you the power of vagrant we insist you to take a look.
Do not make any changes to a vm from virtualbox interface and only manage it with vagrant.
 Open virtualbox software and you will see two vm’s running there.

Visualpath Training & Consulting.


Flat no: 205, Nilgiri Block,Aditya Enclave, Ameerpet, Hyderabad, Phone No: - +91-970 445 5959, 961 824 5689 E-
Mail ID : [email protected], Website : www.visualpath.in.
12. Teardown.
We now have a fully functional virtual machine which we can use for our any DevOps, Ops or
development task. Once we are done with our experiments we may need to suspend, shutdown or
delete the vm. With Vagrant, you suspend, halt, or destroy the guest machine. Each of these options
have pros and cons. Choose the method that works best for you.
Halting.
 Hit “exit” command to come out of the vm shell => hit “vagrant halt” to shut it down.

Visualpath Training & Consulting.


Flat no: 205, Nilgiri Block,Aditya Enclave, Ameerpet, Hyderabad, Phone No: - +91-970 445 5959, 961 824 5689 E-
Mail ID : [email protected], Website : www.visualpath.in.
Suspending the virtual machine by calling vagrant suspend will save the current running state of
the machine and stop it. When you are ready to begin working again, just run vagrant up, and it
will be resumed from where you left off. The main benefit of this method is that it is super-fast,
usually taking only 5 to 10 seconds to stop and start your work. The downside is that the
virtual machine still eats up your disk space, and requires even more disk space to store all the
state of the virtual machine RAM on disk.

Halting the virtual machine by calling vagrant halt will gracefully shut down the guest operating

system and power down the guest machine. You can use vagrant up when you are ready to boot

it again. The benefit of this method is that it will cleanly shut down your machine, preserving

the contents of disk, and allowing it to be cleanly started again. The downside is that it'll take

some extra time to start from a cold boot, and the guest machine still consumes disk space.

Destroying the virtual machine by calling vagrant destroy will remove all traces of the guest

machine from your system. It'll stop the guest machine, power it down, and remove all of the

guest hard disks. Again, when you are ready to work again, just issue v agrant up. The benefit of

this is that no cruft is left on your machine. The disk space and RAM consumed by the guest

machine is reclaimed and your host machine is left clean. The downside is that vagrant up to get

working again will take some extra time since it has to reimport the machine and re-provision

it.

Visualpath Training & Consulting.


Flat no: 205, Nilgiri Block,Aditya Enclave, Ameerpet, Hyderabad, Phone No: - +91-970 445 5959, 961 824 5689 E-
Mail ID : [email protected], Website : www.visualpath.in.
13. Vagrant box commands
In above exercise, we have seen mentioning the box name in the vagrantfile lets us pull-down the
box from vagrant cloud and spin a vm for us when executing vagrant up command.
But sometimes you may need to download the box in advance, may keep record of all the
downloaded box or may even delete a box.
We can use vagrant box command to manage our boxes.
Listing local boxes.
❖ Enter vagrant box list command to see the downloaded box in your system.

Adding a box
We can also download a box and can be used later in our vagrantfile.
Boxes in vagrant cloud and different providers like virtualbox, libvirt, vmware desktop etc.
We may also need to select the provider of the box.

Other box options.

Visualpath Training & Consulting.


Flat no: 205, Nilgiri Block,Aditya Enclave, Ameerpet, Hyderabad, Phone No: - +91-970 445 5959, 961 824 5689 E-
Mail ID : [email protected], Website : www.visualpath.in.
14. Useful Vagranfile settings.
We may need to modify settings of the vm created by vagrant through Vagrantfile.
Few of the generally used settings are mentioned below. To know list of all the settings please refer
vagrant documentation.

Vagrant reload
After changing any vm setting in the vagrantfile, you may need to reload its changes to an already
running vm.
Vagrant reload command will reboot the vm and load all the latest changes, you may need to
provide a --provision option to force the provisioners to run.

Memory/RAM modification.
➔ Open your vagrantfile and find config.vm.provider setting.

➔ Uncomment below mentioned three lines of code and change vb.memory as per requirement.

➔ Run vagrant up if the vm is halted or vagrant reload if the vm is already running. Verify the Base
memory setting from virtualbox.

Visualpath Training & Consulting.


Flat no: 205, Nilgiri Block,Aditya Enclave, Ameerpet, Hyderabad, Phone No: - +91-970 445 5959, 961 824 5689 E-
Mail ID : [email protected], Website : www.visualpath.in.
➔ Login to the vm and run “free -m” command to check total memory size of a linux vm.

15. Bridge Networking.


Vagrant vm will by default have NAT Interface, we can create an extra bridge interface.
Benefit of bridge interface: Our vm will get IP from Router/Gateway/DHCP/Wifi router of our
network. So our VM will be able to talk to any instance in network and vice versa.
Procedure to create bridge network interface:
➔ Open the Vagrantfile of an instance on which you want to create bridge interface.
➔ Enable Public network setting in Vagrantfile by uncommenting below mentioned line.
➔ Uncomment config.vm.network “public_network”

➔ Uncomment config.vm.network “public_network”.

Visualpath Training & Consulting.


Flat no: 205, Nilgiri Block,Aditya Enclave, Ameerpet, Hyderabad, Phone No: - +91-970 445 5959, 961 824 5689 E-
Mail ID : [email protected], Website : www.visualpath.in.
➔ If the VM in powered off you can hit “vagrant up”.
➔ If the vm is already running you need to reload vm with new settings.

➔ Observe it creates one more extra interface “Adapter 2: bridged”.

➔ Login to vm and check its IP, you will see eth1 as bridged interface and will get IP from your
networks

Visualpath Training & Consulting.


Flat no: 205, Nilgiri Block,Aditya Enclave, Ameerpet, Hyderabad, Phone No: - +91-970 445 5959, 961 824 5689 E-
Mail ID : [email protected], Website : www.visualpath.in.
Router/Gateway/DHCP/Wifi router.
➔ Verify from Virtualbox as well.
Select your VM => Settings => Network => Adapert 2

➔ Connecting or ssh to vm with bridge IP.

Visualpath Training & Consulting.


Flat no: 205, Nilgiri Block,Aditya Enclave, Ameerpet, Hyderabad, Phone No: - +91-970 445 5959, 961 824 5689 E-
Mail ID : [email protected], Website : www.visualpath.in.
Vagrant will auto create a user on all vagrant vm’s.
Username => vagrant, Password => vagrant .

16. Provisioning
Provisioning helps execute command or script as soon as the vm comes up.
Provisioners in Vagrant allow you to automatically install software, alter configurations, and more
on the machine as part of the vagrant up process.

This is useful since boxes typically are not built perfectly for your use case. Of course, if you want
to just use vagrant ssh and install the software by hand, that works. But by using the
provisioning systems built-in to Vagrant, it automates the process so that it is repeatable. Most
importantly, it requires no human interaction, so you can vagrant destroy and vagrant
up and have a fully ready-to-go work environment with a single command. Powerful.

Vagrant gives you multiple options for provisioning the machine, from simple shell scripts to more
complex, industry-standard configuration management systems.

Setting up apache/httpd service in a centos vm.


➔ Find config.vm.provision setting.

Visualpath Training & Consulting.


Flat no: 205, Nilgiri Block,Aditya Enclave, Ameerpet, Hyderabad, Phone No: - +91-970 445 5959, 961 824 5689 E-
Mail ID : [email protected], Website : www.visualpath.in.
➔ Update the file with below mentioned content.

➔ Reload the vm and check the provisioning.

➔ Login to vm and verify httpd & iptables service status.

➔ Verify apache default page by providing vm’s bridge ip in browser.

Visualpath Training & Consulting.


Flat no: 205, Nilgiri Block,Aditya Enclave, Ameerpet, Hyderabad, Phone No: - +91-970 445 5959, 961 824 5689 E-
Mail ID : [email protected], Website : www.visualpath.in.
17. External Script
The shell provisioner can also take an option specifying a path to a shell script on the host machine.
Vagrant will then upload this script into the guest and execute it. An example:
Vagrant.configure("2") do |config|

config.vm.provision "shell", path: "script.sh"

end

Relative paths, such as above, are expanded relative to the location of the root Vagrantfile for your
project. Absolute paths can also be used, as well as shortcuts such as ~ (home directory) and
..(parent directory).

18. Synced Folders


Synced folders enable Vagrant to sync a folder on the host machine to the guest machine, allowing
you to continue working on your project's files on your host machine, but use the resources in the
guest machine to compile or run your project.
By default, Vagrant will share your project directory (the directory with the Vagrantfile) to
/vagrant.

Configuration
Synced folders are configured within your Vagrantfile using the config.vm.synced_folder
method. Usage of the configuration directive is very simple:

Visualpath Training & Consulting.


Flat no: 205, Nilgiri Block,Aditya Enclave, Ameerpet, Hyderabad, Phone No: - +91-970 445 5959, 961 824 5689 E-
Mail ID : [email protected], Website : www.visualpath.in.
Vagrant.configure("2") do |config|

# other config here

config.vm.synced_folder "src/", "/srv/website"

end

The first parameter is a path to a directory on the host machine. If the path is relative, it is relative to
the project root. The second parameter must be an absolute path of where to share the folder within
the guest machine. This folder will be created (recursively, if it must) if it does not exist.

19. Defining Multiple Machines


Multiple machines are defined within the same project Vagrantfile using the
config.vm.define method call. This configuration directive is a little funny, because it
creates a Vagrant configuration within a configuration. An example shows this best:

Vagrant.configure("2") do |config|

config.vm.provision "shell", inline: "echo Hello"

config.vm.define "web" do |web|

web.vm.box = "apache"

end

config.vm.define "db" do |db|

db.vm.box = "mysql"

end

end

As you can see, config.vm.define takes a block with another variable. This variable, such as
web above, is the exact same as the config variable, except any configuration of the inner
variable applies only to the machine being defined. Therefore, any configuration on web will only
affect the web machine.

Visualpath Training & Consulting.


Flat no: 205, Nilgiri Block,Aditya Enclave, Ameerpet, Hyderabad, Phone No: - +91-970 445 5959, 961 824 5689 E-
Mail ID : [email protected], Website : www.visualpath.in.
20. Controlling Multiple Machines
The moment more than one machine is defined within a Vagrantfile, the usage of the various
vagrant commands changes slightly. The change should be mostly intuitive.

Commands that only make sense to target a single machine, such as vagrant ssh, now require
the name of the machine to control. Using the example above, you would say vagrant ssh
web or vagrant ssh db.

Other commands, such as vagrant up, operate on every machine by default. So if you ran
vagrant up, Vagrant would bring up both the web and DB machine. You could also optionally
be specific and say vagrant up web or vagrant up db.

21. Forwarded Ports


Network identifier: forwarded_port

Vagrant forwarded ports allow you to access a port on your host machine and have all data
forwarded to a port on the guest machine, over either TCP or UDP.
For example: If the guest machine is running a web server listening on port 80, you can make a
forwarded port mapping to port 8080 (or anything) on your host machine. You can then open your
browser to localhost:8080 and browse the website, while all actual network data is being sent
to the guest.

Defining a Forwarded Port


The forwarded port configuration expects two parameters, the port on the guest and the port on the
host. Example:
Vagrant.configure("2") do |config|

config.vm.network "forwarded_port", guest: 80, host: 8080

end

This will allow accessing port 80 on the guest via port 8080 on the host.

22. Few Sample Vagrantfile’s


Multivm Vagrantfile, every vm with its own custom setting.
Vagrant.configure("2") do |config|

config.vm.define "web" do |web|

web.vm.box = "ubuntu/trusty64"

web.vm.hostname = 'web'

web.vm.network "public_network", bridge: "wlo1"

Visualpath Training & Consulting.


Flat no: 205, Nilgiri Block,Aditya Enclave, Ameerpet, Hyderabad, Phone No: - +91-970 445 5959, 961 824 5689 E-
Mail ID : [email protected], Website : www.visualpath.in.
web.vm.provision :shell, path: "bootstrap.sh"

web.vm.network :forwarded_port, guest: 80, host: 4567

web.vm.provider :virtualbox do |v|

v.customize ["modifyvm", :id, "--memory", 512]

end

end

config.vm.define "db" do |db|

db.vm.box = "ubuntu/trusty64"

db.vm.hostname = 'db'

db.vm.network "public_network", bridge: "wlo1"

db.vm.provider :virtualbox do |v|

v.customize ["modifyvm", :id, "--memory", 512]

end

end

end

Vagrantfile to setup three nodes with custom synced directory and private
network.
# README

# Getting Started:

# 1. vagrant plugin install vagrant-hostmanager

# 2. vagrant up

# 8. vagrant ssh

# This should put you at the control host

# with access, by name, to other vms

Vagrant.configure(2) do |config|

config.hostmanager.enabled = true

Visualpath Training & Consulting.


Flat no: 205, Nilgiri Block,Aditya Enclave, Ameerpet, Hyderabad, Phone No: - +91-970 445 5959, 961 824 5689 E-
Mail ID : [email protected], Website : www.visualpath.in.
# config.vm.box = "nrel/CentOS-6.5-x86_64"

config.vm.define "puppetmaster", primary: true do |h|

h.vm.box = "nrel/CentOS-6.5-x86_64"

h.vm.network "private_network", ip: "192.168.8.10"

h.vm.provider :virtualbox do |vb|

vb.customize ["modifyvm", :id, "--memory", "2048"]

end

h.vm.hostname = 'puppetmaster'

h.vm.synced_folder "puppet_repo", "/etc/puppet"

end

config.vm.define "lamp" do |h|

h.vm.box = "nrel/CentOS-6.5-x86_64"

h.vm.network "private_network", ip: "192.168.8.11"

h.vm.hostname = 'lamp'

end

config.vm.define "lamptest" do |h|

h.vm.box = "ubuntu/trusty64"

h.vm.network "private_network", ip: "192.168.8.12"

h.vm.hostname = 'lamptest'

end

end

Vagrantfile to setup 5 nodes.


Provisioning shell script to do SSH key exchange from autoserver to other 4
nodes.

# README

# Getting Started:

Visualpath Training & Consulting.


Flat no: 205, Nilgiri Block,Aditya Enclave, Ameerpet, Hyderabad, Phone No: - +91-970 445 5959, 961 824 5689 E-
Mail ID : [email protected], Website : www.visualpath.in.
# 1. vagrant plugin install vagrant-hostmanager

# 2. vagrant up

# 3. vagrant ssh

# This should put you at the autoserver host

# with access, by name, to other vms

Vagrant.configure(2) do |config|

config.hostmanager.enabled = true

config.vm.box = "ubuntu/trusty64"

config.vm.define "autoserver", primary: true do |h|

h.vm.network "private_network", ip: "192.168.2.35"

h.vm.hostname = 'autoserver'

h.vm.synced_folder "../autoserver_home", "/home/vagrant/repo"

h.vm.provision :shell, :inline => <<'EOF'

if [ ! -f "/home/vagrant/.ssh/id_rsa" ]; then

ssh-keygen -t rsa -N "" -f /home/vagrant/.ssh/id_rsa

fi

cp /home/vagrant/.ssh/id_rsa.pub /vagrant/autoserver.pub

cat << 'SSHEOF' > /home/vagrant/.ssh/config

Host *

StrictHostKeyChecking no

UserKnownHostsFile=/dev/null

SSHEOF

chown -R vagrant:vagrant /home/vagrant/.ssh/

EOF

end

config.vm.define "nginx0101" do |h|

h.vm.network "private_network", ip: "192.168.2.36"

h.vm.hostname = 'nginx0101'

Visualpath Training & Consulting.


Flat no: 205, Nilgiri Block,Aditya Enclave, Ameerpet, Hyderabad, Phone No: - +91-970 445 5959, 961 824 5689 E-
Mail ID : [email protected], Website : www.visualpath.in.
h.vm.provision :shell, inline: 'cat /vagrant/autoserver.pub >>
/home/vagrant/.ssh/authorized_keys'

end

config.vm.define "apache01" do |h|

h.vm.network "private_network", ip: "192.168.2.37"

h.vm.hostname = 'apache01'

h.vm.provision :shell, inline: 'cat /vagrant/autoserver.pub >>


/home/vagrant/.ssh/authorized_keys'

end

config.vm.define "apache02" do |h|

h.vm.network "private_network", ip: "192.168.2.38"

h.vm.hostname = 'apache02'

h.vm.provision :shell, inline: 'cat /vagrant/autoserver.pub >>


/home/vagrant/.ssh/authorized_keys'

end

config.vm.define "mysql01" do |h|

h.vm.network "private_network", ip: "192.168.2.39"

h.vm.hostname = 'mysql01'

h.vm.provision :shell, inline: 'cat /vagrant/autoserver.pub >>


/home/vagrant/.ssh/authorized_keys'

end

end

Summary:
✓ Virtualization gave us the power of deploying multiple app in one physical server each
having their own OS.
✓ Hypervisor gives us power and interface to create multiple virtual server also known as VM
on one physical machine.
✓ There are two types of hypervisor, type1 which is installed directly on Hardware and type 2
which gets installed on a host OS.
✓ Virtualbox is type 2 hypervisor which can be installed on Linux and windows machine's.
✓ We can create & manage VM’s and their resources like virtual hard disk, Memory, Vcpu,
network etc through virtualbox interface.
✓ Creating & Managing lot vm from virtualbox interface is time consuming and mundane
task.

Visualpath Training & Consulting.


Flat no: 205, Nilgiri Block,Aditya Enclave, Ameerpet, Hyderabad, Phone No: - +91-970 445 5959, 961 824 5689 E-
Mail ID : [email protected], Website : www.visualpath.in.
✓ Vagrant is a command line tool that helps us create & manage virtual machine lifecycle
automatically.
✓ Vagrantcloud hosts many of vm images AKA boxes which can be used by anyone using
Vagrant tool. We don’t do OS installation anymore with Vagrant, we just pull vagrant box
images and run them.
✓ Vagrantfile is the single source of truth for your VM’s in Vagrant. We can mention box
name, its memory, network and other settings while spinning a VM in the Vagrantfile.
✓ Vagrantfile gives us the feature of provisioning by which we can run any automation script
to configure VM after vm comes up.
✓ Multiple VM’s can be managed by a single Vagrantfile.

Conclusion:
Vagrant is a great tool for our day to day DevOps tasks Maybe you have written a script for
deployment or maybe you are learning any new devops tool, to test all these things you need VM’s.
With Vagrant, we can quickly set up multiple vm’s and start practicing. It’s part of our daily toolkit.
We can also use Ansible, Chef or Puppet code in provisioning part of the Vagrantfile, once we learn
these tools in later chapters you can go ahead and try those. Vagrant can also be used to provision
instances on AWS cloud.
If you are working in DevOps you will encounter with local virtual machines, always use Vagrant
to maintain your local vm setup.

Visualpath Training & Consulting.


Flat no: 205, Nilgiri Block,Aditya Enclave, Ameerpet, Hyderabad, Phone No: - +91-970 445 5959, 961 824 5689 E-
Mail ID : [email protected], Website : www.visualpath.in.

You might also like