A Quick Insight on Vagrant

Vagrant is a tool enables users to create and configure lightweight, reproducible, and portable development environments and controlled by a single consistent workflow to help maximize the productivity and flexibility of you and your team. Vagrant became part of the HashiCorp Tools list and it is developing and maintained by HashiCorp team.

It’s a CLI-based tool for streamlining the use of VM environments (creation, provisioning, usage, & decommissioning). Vagrant uses VirtualBox to build configurable, lightweight and portable virtual machines dynamically. It also supports more providers recently : VMWare, AWS EC2, RackSpace.

I will provide a quick insight on Vagrant to give you better understanding on Vagrant and it’s use.

Why Vagrant?

For Developers : Vagrant will isolate dependencies and their configuration within a single disposable, consistent environment in a Single Vagrantfile. The same file can be used all the developers and provision the environment locally in your working machine and say good bye to “works on my machine

For Operations Engineers : Vagrant gives you a disposable environment and consistent workflow for developing and testing infrastructure management scripts at “zero cost”. You can quickly test things like shell scripts, Chef cookbooks, Puppet modules, and more using local virtualization.

No more ‘It works for me’ reports; Oh ‘ No, I was using PHP 5.3.3, not PHP 5.3.11’


  • Installing Vagrant is extremely easy
  • Download the Vagrant from this Location : https://www.vagrantup.com/downloads.htmlVagrant Installation
  • The default Installation Location : C:\HashiCorp\Vagrant
  • The installer will automatically add vagrant to your system path so that it is available in terminals.
  • If not, switch to Installation directory or provide full path to test the installation is successful.

Picture2 Picture3




Getting Started

  • To make an Ubuntu Instance UP AND RUNNING, run the below two simple commands from your preferred location.Ubuntu Installation
    • vagrant init hashicorp/precise64
    • vagrant up
  • In your current current directory, you will see this directory and config file.
    • .vagrant
    • Vagrantfile
  • After running the above two commands, you will have a fully running virtual machine in VirtualBox running Ubuntu 12.04 LTS 64-bit
  • You can SSH into this machine with vagrant ssh from the same current directory


  • We could just SSH in and install any package or run/configure any service and be on our way, but then there is no difference between using Vagrant than any other method of installation and configuration.
  • Vagrant has built-in support for automated provisioning. Using this feature, Vagrant will automatically install/configure software, run scripts and services. When you do vagrant up so that the guest machine can be repeatably created and ready-to-use.
  • Create your shell scripts and save it as <script>.sh in the same directory as your Vagrantfile:
  • Edit the Vagrantfile which should now look like this:
     config.vm.provision :shell, path: “helloworld.sh“
  • Machine provision is first time, please proceed with the standard commands like “vagrant up “ or if it is a change to the existing machine run as : “vagrant reload –provision“

Vagrant Share

  • Vagrant Share allows you to share your Vagrant environment with anyone in the world, enabling collaboration directly in your Vagrant environment with just a single command: vagrant share.
  • Vagrant share has three primary modes or features:
    • HTTP sharingwill create a URL that you can give to anyone. This URL will route directly into your Vagrant environment. This is useful for testing webhooks or showing your work to clients, teammates, managers, etc.
    • SSH sharing will allow instant SSH access to your Vagrant environment by anyone by running vagrant connect –ssh on the remote side. This is useful for pair programming, debugging ops problems, etc.
    • General sharing allows anyone to access any exposed port of your Vagrant environment by running vagrant connect on the remote side.
  • Vagrant Share requires an account with HashiCorp’s Atlas to be used.
Vagrant Share – HTTP
  • Share the active HTTP server in your environment.
  • Run vagrant login and enter your Atlas by HashiCorp details
  • Boot a Vagrant environment and verify it’s running an HTTP server
  • Run vagrant share. You’re done!
Vagrant Share – SSH
  • Share SSH access to your environment.
  • Run vagrant login and enter your Atlas by HashiCorp details
  • Boot a Vagrant environment
  • Run vagrant share –ssh
  • Enter a password for encrypting the SSH key
  • Give your Share name and the password to a friend and have them run vagrant connect –ssh [SHARE NAME]
Vagrant Share – Connect
  • Share any port in your environment.
  • Run vagrant login and enter your Atlas by HashiCorp details
  • Boot a Vagrant environment
  • Run vagrant share –disable-http
  • Give your Share name to a friend and have them run vagrant connect [SHARE NAME]


  • 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. The actual literal filename for the file is Vagrantfile
  • Vagrant is meant to run with one Vagrantfile per project
  • Vagrantfiles are portable across every platform Vagrant supports.
  • In order to access the Vagrant environment created, Vagrant exposes some high-level networking options for things such as forwarded ports, connecting to a public network, or creating a private network.
  • 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.
    config.vm.network forwarded_port“, guest: 80, host: 8080
  • Vagrant private networks allow you to access your guest machine by some address that is not publicly accessible from the global internet.
  • Vagrant public networks are less private than private networks,  The idea is that while private networks should never allow the general public access to your machine, public networks can.
  • The easiest way to use a public network is to allow the IP to be assigned via DHCP. In this case, defining a public network is trivially easy: Using the DHCP Assigned Default Route
    use_dhcp_assigned_default_route: true
  • Vagrant Public Networks are not really publicly accessible, they will be able to accessible within the network of your LAN.

Warning! Vagrant boxes are insecure by default and by design, featuring public passwords, insecure keypairs for SSH access, and potentially allow root access over SSH. With these known credentials, your box is easily accessible by anyone on your network. Before configuring Vagrant to use a public network, consider all potential security implications

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.


  • Boxes are the package format for Vagrant environments. A box can be used by anyone on any platform that Vagrant supports to bring up an identical working environment.
  • The vagrant box utility provides all the functionality for managing boxes.
  • Publicly Available Boxes : https://atlas.hashicorp.com/boxes/search
  • To lists all the boxes that are installed into Vagrant : vagrant box list
  • Creating and Managing Boxes can be found : https://www.vagrantup.com/docs/boxes/base.html

Stay tuned for more updates for “How to integrate Vagrant with Amazon AWS” to take the advantage of Vagrant features in Amazon AWS.

Leave a Comment

Your email address will not be published.