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 production parity, and makes the "works on my machine" excuse a relic of the past.
Vagrant provides easy to configure, reproducible, and portable work environments built on top of industry-standard technology and controlled by a single consistent workflow to help maximize the productivity and flexibility of you and your team.
To achieve its magic, Vagrant stands on the shoulders of giants. Machines are provisioned on top of VirtualBox, VMware, AWS, or any other provider. Then, industry-standard provisioning tools such as shell scripts, Chef, or Puppet, can automatically install and configure software on the virtual machine.
Installation of Vagrant
Vagrant is dependent on Oracle Virtual Box. So we need to install compatible version of Oracle Virtual Box for Vagrant. Download Vagrant from https://www.vagrantup.com/downloads.html and install on your host machine. You may need to reboot your machine to complete Vagrant installation.
Post reboot please test the installation by checking Vagrant version with vagrant –v command.
Vagrant Boxes:
Instead of building a virtual machine from scratch, which would be a slow and tedious process, Vagrant uses a base image to quickly clone a virtual machine. These base images are known as "boxes" in Vagrant, and specifying the box to use for your Vagrant environment is always the first step after creating a new Vagrantfile. We will see usage of vagrant boxes in Project setup.
Project Setup
The first step in configuring any Vagrant project is to create a Vagrantfile. The purpose of the Vagrantfile is twofold:
  1. Mark the root directory of your project. Many of the configuration options in Vagrant are relative to this root directory.
  2. Describe the kind of machine and resources you need to run your project, as well as what software to install and how you want to access it.
Vagrant has a built-in command for initializing a directory for usage with Vagrant: vagrant init. For the purpose of this getting started guide, please follow along in your terminal:
mkdir vagrant_practice
cd vagrant_practice
vagrant init “box_name”
            box_name can be anyname which is available on  https://app.vagrantup.com/boxes/search
example: to create centos7 VM you can chose bento/centos-7.3
vagrant init “bento/centos-7.3”
This will place a Vagrantfile in your current directory. You can take a look at the Vagrantfile if you want, it is filled with comments and examples. Do not be afraid if it looks intimidating, we will modify it soon enough.
You can also run vagrant init in a pre-existing directory to set up Vagrant for an existing project.
The Vagrantfile is meant to be committed to version control with your project, if you use version control. This way, every person working with that project can benefit from Vagrant without any upfront work.
Once we initialize the project we need to bring up the machine.
vagrant up
This will create a running instance form the base image. When you run the command it will check the box availability in local machine if Vagrant unable to find the box it will connect to vagrant central repository and it will pull box.
You can check the status of VM using vagrant status command.
Vagrant will configure passwordless connection from project root directory to your Guest VM. So you can login to Guest VM without any password. To login to Guest VM you can use vagrant ssh command on your cli interface.
You can work on your setup in your Guest VM now.



 << Previous                                                                                                                             Next>>

No comments:

Post a Comment