Easy virtualization with Vagrant

Why Vagrant

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.

Setting Up

First You need to install virtual box or VMware too setup in your host machine.

sudo apt-get install virtualbox

Then Download vagrant deb package

~$ wget  https://releases.hashicorp.com/vagrant/1.9.5/vagrant_1.9.5_x86_64.deb

Then install the debian package

~$ dpkg -i vagrant_1.9.5_x86_64.deb

This will setup vagrant in /opt/vagrant and bin files in /usr/bin/vagrant

Then create a folder for your vagrant environment.

~$ mkdir /opt/environment1
~$ cd /opt/environment1

Initialize the environment as a vagrant environment. This will create the Vagrnatfile in this directory.

/opt/environment1~$ vagrant init

The Vagrantfile configuration needed to be edited. provide name, os package, ram and static/dynamic ip settings.

config.vm.box = "ubuntu/trusty64"
config.vm.hostname = "testVM1"
config.vm.network = "private_network", ip = "192.168.32.15"
vb.memory = "1024"

The ip settings here are for setting up a static ip. if u need DHCP you can keep the configurations as it is.
if you need to set up using an already configured vitual box image or vagrant box iso, then specify it like

config.vm.box = "/PATH_TO_FILE/NAME.box"

Then we have to initialize the vagrant instance. First  see the vagrant has configured the instance that need to be start in this environment.

/opt/environment1~$ vagrant status

Then start the vagrant instance

/opt/environment1~$ vagrant up INSTANCE_NAME

This will create the virtualbox VM for you to work with. after vagrant create the instance simply ssh to the instance

/opt/environment1~$ vagrant ssh INSTANCE_NAME

Now you can work in your vagrant initiated VM and ssh even from host terminals using the static ip that was provided earlier. Enjoy…!!!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s