Ultra fast setup environment with Vagrant and VirtualBox

vagrantI’m doing a few Ansible related courses at the moment and at the start the teacher explains a way to setup a whole test lab in just a couple of minutes. A lab with 3 or more machines, it’s really a piece of cake with Vagrant and VirtualBox. I’m using Kali Linux at the moment, but it will be the same on any other Linux I believe.

I felt a bit behind after watching this course. OK, I know nothing about Ansible, that is the reason I’m watching it. But also this technology, and the speeds in which you can setup a whole lab, I never came across such a system.

Glad to learn something new every day!

Install the software

$ sudo apt-get install vagrant

$ sudo apt-get install virtualbox

We’ll need a config file which you can create with vagrant init. In this file we specify the test machines to use.

$ mkdir Vagrant

$ cd !$

$ vagrant init

$ vi Vagrantfile

Vagrant file contents

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

# All configuration is done below. The “2” in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don’t change it unless you know what
# you’re doing.

Vagrant.configure(“2”) do |config|

config.vm.define “ansible” do |acs|
ansible.vm.box = “ubuntu/trusty64”
ansible.vm.hostname = “acs”
ansible.vm.network “private_network”, ip: “”

config.vm.define “web” do |web|
web.vm.box = “nrel/CentOS-6.5-x86_64”
web.vm.hostname = “web”
web.vm.network “private_network”, ip: “”
web.vm.network “forwarded_port”, guest: 80, host: 8080

config.vm.define “db” do |db|
db.vm.box = “nrel/CentOS-6.5-x86_64”
db.vm.hostname = “db”
db.vm.network “private_network”, ip: “”


Virtual machines

Here we’re specifying 3 machines, 1 Ubuntu and 2 CentOS. These are not the most recent version as you can see but I needed these for my lab. You can find a lot more at this site.

Bring them all up with one command (the first time these images will be downloaded and started):

$ vagrant up

And login in one of them.

$ vagrant ssh ansible

I should say that I normally use VMWare (as pointed out here and here) but I did not try to do the same stuff I do here with Virtualbox, as a test with VMWare. I’m thinking it’s not possible. Technology-wise it has a completely different setup, but I also think that you could have problem licensing-wise. Well anyway, it’s outside the scoop of this post.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.