Deploying with Vagrant and Ansible

Speaker: Yeuk Hon Wong (

This talk was given on April 18, 2013 for Adv Tps Intrnet Prog: CSC I4330 3GG [2337] (CCNY ).


Slides are available on Speakerdeck.


I would call vagrant a wrapper on top of virtual machine manager such as VirtualBox and VMWare. In fact, Vagrant now only support VirtualBox and VMWare officially.

The best feature of vagrant is the notion of "workspace for VM". When you issue vagrant init you will get a configuration file Vagrantfile and a directory called .vagrant which holds the id and possibly other metadata of the VM associated with this workspace.

Vagrant provides official boxes but they are shipped with a default, universal RSA key so do not use official boxes in production. You should build the machine from scratch using veewee or just import the ISO directly into VirtualBox, run Ansible or Puppet or Chef and then package the VM into a base box and use that box as your "official box".

Common commands:

vagrant init   or vagrant init <box-name>
edit Vagrantfile
vagrant up
vagrant ssh
vagrant halt
vagrant destroy


GLASS Lab chose Ansible over Puppet or Chef because:

  1. Ansible has a strong, active community
  2. A few dependencies (jinja2, simplejson/json, Python interpreter, paramiko, pyyaml)
  3. Core is much smaller than others (and in Python!)
  4. Configuration in plaintext - no Ruby, no custom DSL, easy, not even Python Fabric

Example Playbook

The example playbook is used to show how quickly it is to get started with Ansible in 15 minutes once you are familiar with the syntax. The repo is a project I am working on in my class. Note that you should not dump everything into a single .yml file. There is a better way to handle structure (although I still recommend use whatever works for you) and you can read about that in the Documentation.


First, install Vagrant and Ansible.

We need to get a machine up and running:

mkdir newdir-name
cd newdir-name
vagrant box add precise32
vagrant init precise32
(edit Vagrantfile if you want to set smaller memory, or get public ip, e.g LAN ip)
vagrant up

Then we need to learn the IP assigned:

vagrant ssh

Edit hosts file and change the IP to the new IP you obtained above.

Finally, you can run:

ansible-playbook -i hosts main.yml -u vagrant -k

where the SSH password is vagrant (that's the default user/pwd for an official box).