HomeLinux Administration

Vagrant Introduction | Configuring and Managing Vagrant Environments

Vagrant Introduction | Configuring and Managing Vagrant Environments
Like Tweet Pin it Share Share Email
Personal Development Category (English)728x90

In this article, I am going to teach you about the quick introduction of the Vagrant and the settings, configurations, and managing the vagrant Environments.

Vagrant environmentsWhat is Vagrant?

Vagrant is an open source tool for working with virtual environments. Vagrant acts as a wrapper and sits on top of the virtualization solution (VMware, Hyper-V, VirtualBox or libvirt)  and provides a simple command line interface to manage the VM’s with the custom configuration.

 

 

Why we use Vagrant?

  •  No need to learn different CLI command of Virtualization providers, vagrant takes cares to manage the underlying VM’s with its easy CLI interface.
  • Well defined environments as configuration used to create the environments are in simple text files.  The user can recreate as many Vagrant Instances (VMs)  using the same Vagrant file.
  • Vagrant is capable of executing configuration management software like Puppet/Ansible/Chef once the base system is ready (using the box). This help o setup the environment (System + Application) on the target machines in an automated way.
  • Developer can create/destroy multiple development environments in minutes.
  • As vagrant is wrapper only, you can choose the guest OS images supported by the virtualization platform you choice. Example on CentOS 7, you may run CentOS 6 VM.

How does Vagrant work?

Vagrant performs the following tasks with the single command:

  • Creates a VM using base images.
  • Configures the virtual machine specific settings and configuration using the Vagrantfile.
  • Automates the configuration management of the virtual machine using the configuration management software.

Workflow: the below image will explain how Vagrant environments will look like.

Vagrant environments

Vagrant Terminology:

Box: A box is a packaged Vagrant environment, typically a virtual machine.

Provider: A provider provides virtualization support. Providers can be of 02 types;

  •  Local:  VirtualBox,VMware,Docker,Hyper-V
  •  Remote:  AWS Cloud, Openstack

Vagrantfile:  Configuration file for the target machine’s config. Contains information like

  • Which Base Image to use.
  • What will be the hostname?
  • What will be the network?
  • Any specific compute.
  • Provisioner Config (Shell/Automation Tools)

Provisioner:   A provisioner is a tool to set up the virtual environment and can be as simple as a   shell script, also it can be automation toll-like Chef, Ansible or Puppet.

The example of Shell Provisioner:

 

The Example of Automation Tool Provisioner:

 

 

LAB Details  and Pre-Req’s:

In this session, I am going to demonstrate vagrant on a Linux machine. Details are:

Host:  CentOS 7.3 x86_64

Host Platform:  VMware Workstation 12

Hardware Virtualization:  AMD-v/Intel VT-x

Host Network:   VM have 02 vNICs

  •  vNIC1 : Host Only (Host Only Connectivity)  90.10.10.10/24
  •  vNIC2 : Bridged  (Internet Connectivity)     192.168.1.20/24

VirtualBox Version   :   5.1.x86_64

Vagrant Version:   1.9.3

Also, Check out the Video for more details:

Vagrant environments

Update the system and install the pre-req packages for VirtualBox to work.

 

Not mandatory, but let’s install “X Windows”, to easily look into the VirtualBox issues if any.

 

Take a reboot of the system.

 

Vagrant Installation:

1. Download the latest available versions of Virtualbox and Vagrant software from the download pages of the products.

2. Once software installers downloaded (they are rpm’s generally), transfer those to the machine and it is going to be configured as a Vagrant server.

3. Install the Virtualbox and Vagrant RPM.

“vboxconfig” will install, configure the virtualbox modules and start the service.

Validate the Installation:

vboxmanage is the CLI provided by the VirtualBox package.

Downloading Base Image:

Though you can build a virtual machine from scratch, but that is going to a time taking process. You can find different images from Atlas ( Vagrant Repo) for your Virtualization Provider.

Vagrant uses a base image to quickly clone a virtual machine. These base images are known as “boxes”.

Vagrant Image Repository:

https://atlas.hashicorp.com/boxes/search?_ga=1.263880075.66532464.1491004385

To download the base Image

 

Note – In the above example, we are downloading base image with name “centos/7”.

Image download will take some time depending on your internet connectivity as Image will download the Atlas repo.

Once box downloads successful, you can validate it by running the below command.

 

Set the Path of Virtual Machine

Initializes a new Vagrant environment:

Example:

“vagrant init “ creates Vagrantfile in the current directory, you can customize the file as per requirement.

Start and provision the vagrant environment:

 

Connect to the machine via SSH:

Please Note – when you run multiple vagrant machines, vagrant allocates new SSH port forwarding for every machine.

Default credentials for the Vagrant machine are generally “vagrant/vagrant”.

1. List all the VMs:

 

2. To know the vagrant port mapping:

 

3. To display IP address of guest machine:

 

Please Note – you need to install “vagrant-ip-show” before you run the below-mentioned command.

 

Often used Vagrant CLI commands: This below commands will help you to handle Vagrant environments.

1. Outputs status of the vagrant machine:

 

2. Outputs status Vagrant environments for this user:

 

3. Starts and provisions the vagrant environment:

 

4. Stops the vagrant machine:

 

5. Suspends the machine:

 

6. Stops and deletes all traces of the vagrant machine:

 

7. Restarts vagrant machine loads new Vagrantfile config:

 

8. Displays information about guest port mappings:

 

Summary: In this article, I have tried to explain you the Vagrant Environments and how it will useful for everyone. Check out the Vagrant video for more details and if you have any suggestion/queries please comment on below. I will help you out to provide the response as my best.

Comments (3)

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.