Pages

Saturday, December 26, 2015

Vagrant – Basics

Vagrant is an Open Source tool for building and managing virtualized development environments. In other words vagrant is used to create Virtual machines. A virtual machine is a software implementation of a computer, running a complete operating system stack on a virtualizer. Virtuals configured by Vagrant are hosted on Oracle virtual Box which is a virtualizer and open source provided by Oracle.

The virtual machine is generally a full implementation of the Computer with a Disk, memory and CPU. The machine running the virtualizer is the Host system. The virtual machine running on the virtualizer is the Guest system. As far as the Guest operating system is concerned, it is running on real hardware. From the perspective of the Host, all of the Guest's resources are used by the virtualizer program. A Box, or base image, is the prepackaged virtual machine that Vagrant will manage.

In other words, vagrant is used to Create and configure lightweight, reproducible, and portable development environments. This article will tell you on how to configure the Vagrant Virtuals and basic usage of them.

1) Installing vagrant
Vagrant can be downloaded from here. Choose the packages based on your Operating system and download them.

2) Once downloaded as an RPM for *nix based OS, run the yum command for installing the vagrant. Once installed, run the

[root@vx111a Downloads]# vagrant -v
Vagrant 1.7.4

We can see the commands available with vagrant using

[root@vx111a ~]# vagrant list-commands
Below is a listing of all available Vagrant commands and a brief description of what they do.

box
 manages boxes installation, removal, etc.
connect
 connect to a remotely shared Vagrant environment
destroy
 stops and deletes all traces of the vagrant machine
docker-logs
 outputs the logs from the Docker container
docker-run
 run a one-off command in the context of a container
global-status
 outputs status Vagrant environments for this user
halt
 stops the vagrant machine
help
 shows the help for a subcommand
init
 initializes a new Vagrant environment by creating a Vagrantfile
list-commands
 outputs all available Vagrant subcommands, even non-primary ones
login
 log in to HashiCorp's Atlas
package
 packages a running vagrant environment into a box
plugin
 manages plugins install, uninstall, update, etc.
provision
 provisions the vagrant machine
push
 deploys code in this environment to a configured destination
rdp
 connects to machine via RDP
reload
 restarts vagrant machine, loads new Vagrantfile configuration
resume
 resume a suspended vagrant machine
rsync
 syncs rsync synced folders to remote machine
rsync-auto
 syncs rsync synced folders automatically when files change
share
 share your Vagrant environment with anyone in the world
ssh
 connects to machine via SSH
ssh-config
 outputs OpenSSH valid configuration to connect to the machine
status
 outputs status of the vagrant machine
suspend
 suspends the machine
up
 starts and provisions the vagrant environment
version
 prints current and latest Vagrant version

Terminology of Vagrant
Before starting with the vagrant we need to understand few basic terms of vagrant.

Providers – these are the components that enable vagrant to use a different virtulization. That is as said above we will be using the oracle virtual Box while working with vagrant. Oracle virtual box is one vagrant supported software hypervisor. Vagrant supports other hypervisors too like Hyper-V. Additional Providers can also be added by plugin mechanism. For example you can add support for VMWare products as well as IaaS providers such as AWS

Provisioners – These allows vagrant to bring machine to a desired state. This can be done by executing simple shell scripts or a different configuration management tools such as puppet and Check. Provisioning in Vagrant usually happens after machine initialization but can be initiated on demand.

boxes – a Box in vagrant is a package that are bundled with provider specific machine data. That is considering a CentOs box which contains Centos operatins system and certain modifications. These boxes are used in creating similar vagrant virtual machines by importing them.

Vagrant plugins – Plugin in Vagrant provides extendability via its plugins API. This creates possibilities to add support for new provisioners, providers and other utilities

We can use the command “vagrant plugin list” to see the available plugins.
Shared/Synced folders – Vagrant allows sharing or syncing of folders from host machine to guest machine. This allows you to edit your files locally and see the changes in the guest machine. This is based on the provider for example virtual Box provides the shared folder mechanism. Vagrant also allows syncing by using tools such as rsync or network file share using NFS.

Port forwarding – This is one of the important feature that used with networking in vagrant.
Some providers such as VirtualBox allow running VMs in NAT network mode. In this mode the VM sits in its own private address space which is not accessible from the host machine. In this case port forwarding allows creating forwarding rules that will forward traffic from local port to the port of the virtual machine.

Hope this helps in understanding the basic concepts of Vagrant. In the next article we will see how to set our first vagrant machine.

No comments :

Post a Comment