I'm a big fan of the DevOps attitude of "cattle" versus "pets": machines should be built in a repeatable, automated and consistent way. If there's something wrong, don't be afraid to replace a sick "cow" instead of trying to revive your "pet".

This Zen mindset also helps when preparing for demos, trainings and workshops: Usually I need a number of machines, and what better way than create them by using automation ? For that I'm using the tools Ansible, Packer, Vagrant and VirtualBox - they are all Open Source and can be used on a number of platforms (e.g. Windows, Linux and Mac OS X).

Ansible is a tool for managing systems and deploying applications, licensed under the GNU General Public License version 3 (my personal favorite).

Vagrant is a tool for managing virtual machines and is licensed under the MIT license.

VirtualBox is a virtualization environment for local use, licensed under the GNU General Public License version 2.

Packer creates a machine image by installing an operating system to a multitude of local and cloud platforms, for example VMWare, VirtualBox as well as Docker, Amazon EC2 and DigitalOcean. Packer is licensed under the Mozilla Public License Version 2.0.

How to solve the bootstrap problem and use Ansible to provision machines if you haven't got Ansible installed (yet) ?

This post contains the two (!) simple steps on how to set up a Vagrant Box containing an Ansible server, packaged as a Vagrant box. This allows you to use Ansible for provisioning all of your (future) (VirtualBox) installations.


  • Make sure that the following tools are installed, up-to-date and can be executed from the command line.

    Vagrant : https://www.vagrantup.com (to configure and spin up virtual machines)

    VirtualBox : https://www.virtualbox.org/wiki/Downloads (the virtualization environment)

  • Start your favorite shell (e.g. zsh or Bash), and verify that the tools are working:

    vagrant version && VBoxManage --version && echo "Hey Ho Let's Go"
  • Clone the repository containing the necessary Ansible and Vagrant files:

    git clone https://github.com/PeterMosmans/easy-provisioning && pushd

1a: Build and provision Ansible on Debian

Before you start, if you want to add your own user account and public SSH key to the Ansible server, create the file

- there is an example called ansible/group_vars/personal-example.yml in the repository (see for more information the corresponding Ansible Galaxy role, bootstrap).

The following one-liner will spin up a Debian box named

, install Ansible on it, and provision it for use with VirtualBox. It will also compact the box, and shut it down:

pushd vagrant/ansible-server && VAGRANT_VAGRANTFILE=Vagrantfile.bootstrap
vagrant up

What happens ? By using the

environment variable, an alternative Vagrantfile is specified,
. This file contains parameters that will download a stock Debian installation, installs the pip version of Ansible, installs the Ansible Galaxy roles specified in
, runs the playbook
, and runs a script to compact the box (that was installed by one of the Ansible roles).

1b: Package the Ansible server

Use the following one-liner command to package the Ansible server as a new Vagrantbox, and add it to the local catalog, ready to be used:
VAGRANT_VAGRANTFILE=Vagrantfile.bootstrap vagrant package bootstrap --output
ansible-server.box && vagrant box add ansible-server.box --name

That's all there is to it! Now, you can spin up the Ansible server box anytime using the command

vagrant up

in the

directory. The directory
in the repository is mapped on the VirtualBox to
, so the data persists across Vagrant 'reboots'.

Optionally you can shut down and remove the bootstrap box (as it's already imported) using
VAGRANT_VAGRANTFILE=Vagrantfile.bootstrap vagrant destroy && rm

Enjoy the Zen and power of Ansible...


comments powered by Disqus