Do less plumbing by using Vagrant

Vagrant makes managing a virtual machine’s (VMs) lifecycle easy by providing simple commands. It lets developers focus on developing rather than plumbing work. Below is a high-level overview of Vagrant with links for further reading.

  • standardization - configure once, use everywhere
    • windows
      • If you need rsync then go with
        • Cygwin
        • MinGW
      • otherwise can make do with
        • putty
    • mac
    • linux
  • reduces overhead - manage VM lifecycle with commands

     vagrant up
     vagrant suspend
     vagrant halt
     vagrant destroy
     vagrant reload
     vagrant status
     vagrant init
     vagrant box list
     vagrant box remove <name-of-box>
     vagrant box add <name-of-box>
     vagrant ssh
     vagrant provision
    
  • wide support
    • out of the box support for the following providers
    • remote clouds
      • AWS EC2
      • Rackspace
    • provisioning tools
      • shell scripts
        • ideal for new users who want to get up and running quickly
      • Ansible
      • Chef
        • vagrant does not automatically install provisioners for chef and puppet
        • need to install it in the base box
      • Puppet
        • vagrant does not automatically install provisioners for chef and puppet
        • need to install it in the base box
        • can use to install services like
          • databases
          • web servers
      • Salt
      • Docker
        • automatically installs Docker
        • can use puppet (installing services) + docker (contain your application) provisioner together
  • share - easy to distribute VMs
    • share box file
    • share vagrant
      • share your vagrant environment
        • SSH sharing
          • remote into your vagrant box
        • HTTP sharing
          • share your webserver links to clients for feedback
  • provides high-level interface to simplify working with VMs
    • synced folders
      • automatically sync files to and from guest machines
      • /vagrant is the shared directory
    • provisioning
      • automatically install software during vagrant up phase
      • use configuration (a.k.a provisioning) tools to automate installation
      • specify configuration using vagrantfile
    • networking
      • exposes high-level networking interface to help you
        • forward ports
        • connecting to a public network
        • creating a private network

Steps for getting started with Vagrant

  1. Download and install Vagrant
  2. Setup Project
  3. Add a box
  4. Vagrant Up

Testing a Box

vagrant box add my-box /path/to/the/new.box

vagrant init my-box

vagrant up

Vagrant Push

  • deploy code residing in same directory as vagrant file to a remote server
  • through

Terms

Vagrantfile

  • file to describe how to configure and provision machines
  • specifies type of machine required for project
  • uses ruby syntax
    • ruby knowledge not required, just simple variable assignments
  • portable

Boxes

  • the base image of a virtual machine
  • can be downloaded from a local file, custom URL or HashiCorp’s Atlas Box Catalog

Base Boxes

  • contains the bare minimum for vagrant to function
  • used as a clean starting point for building new environments
  • are provider specific

Box file format

  • contains two components
    1. Box File
      • required
      • compressed (tar, tar.gz, zip)
      • specific to a single provider (eg. VirtualBox)
    2. Box Catalog Metadata
      • optional but recommended
      • JSON document
      • provide support for multiple providers and versioning

HashiCorp’s Atlas box catalog

  • free public boxes available for download
  • lets you host your own public or private boxes
    • benefits
      • support for versioning, pushing updates, analytics and more

Provisioners

  • lets you automate installation software
  • and alter configuration