César D. Velandia

Vagrant


Intro

A cross-platform tool created by Hashicorp to make configuring and sharing VMs easy by automating VM management with an end-to-end lifecycle management utility. Core benefits of VMs are reproducible environment, isolated and restricted environments, shareable, easy synchronization and consistency (across multiple OS)

Vagrant can be extended via plugins for custom providers, provisioners, commands, and hosts, including Docker.

Components

Vagrantfile

Describes configuration and provisioning of VMs in Ruby. Unique by project describes machine type, image, networking, provider-specific information, and provisioner details. The commands such as  vagrant up look for a configuration file to run the operation, other commonly used commands are ssh, destroy, box, rdp

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure(2) do |config|
   config.vm.box = "centos/7"

   config.vm.network "private_network", ip: "192.168.30.10"
   config.vm.synced_folder "../data", "/vagrant_data"

   config.vm.provider "virtualbox" do |vb|
      vb.memory = "1024"
   end

   config.vm.provision "shell", inline: <<-SHELL
         yum install vim -y
   SHELL
end
A Vagranfile

Boxes

The image to run the VM from. The official repo is located at https://app.vagrantup.com/boxes/search . Box images can be versioned and customized.

Providers

Engines and hypervisors used to provision VMs or containers. Currently supports VirtualBox (default), Hyper-V, and Docker. Other custom providers are available, e.g., KVM, AWS.

Synced Folders

Sync a directory on the host system with a VM, for example: config.vm.synced_folder "../data", "vagrant_data"

Provisioning

Provisioners enable automatic installations and updates to configuration changes after the machine is booted via vagrant up. Examples are:  File, Shell, Ansible, Puppet, Chef, Docker, and Salt.

Plugins

Extends vagrant capabilities. See https://vagrant-lists.github.io/plugins.html

Networking

High-level networking options for port forwarding, network connectivity, and network creation. That is, the same Vagrantfile used to provision a VirtualBox VM could be used to provision a VMware machine.

Multi-Machine

A project's Vagrantfile may describe multiple VMs, that are supposed to interact with each other.

Benefits

  • Automates setting up VMs (speed, highly productive, cost effective)
  • Improves consistency in infrastructure provisioning
  • Flexible and cross-platform.
  • Usable with Docker.
  • Easy install and configuration.
  • Enables collaboration by providing a predictable environment.