Dirty Vagrant

17 May 2017

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.

As it says on tin, Vagrant is a way to spin up VMs quickly in an automated manner. To get started simply:

vagrant init centos/7
vagrant up

This will download the base box from HashiCorp’s public vagrant box server and start the box. The centos/7 box specifically refers to

The newly started box can then be accessed with:

vagrant ssh


The meat and potatoes of the Vagrant experience will be manipulated via the Vagrantfile (created upon running vagrant init).

Here is an example Vagrantfile which will setup two machines and network them together via private interfaces.

Vagrant.configure("2") do |config|
    config.vm.define "dns" do |dns| = "centos/7" "private_network", ip: ""
    config.vm.define "master" do |master| = "centos/7" "private_network", ip: ""
    config.vm.provision :shell, path: ""

This names two machines, instructs Vagrant to base them on the centos/7 box and assigns them static IP addresses on private interfaces.

It also triggers a script to run upon provisioning the box for the first time. In this case the script resides in the same directory as the Vagrantfile and contains some simple bash commands:

cat << EOF > /etc/resolv.conf
search puppet.local

echo "PEERDNS=no" >> /etc/sysconfig/network-scripts/ifcfg-eth0

A provisioning script is definitely not required though!

Read More