Vagrant

First contact was a catastrophe. I did not know what the heck people see in it. I hated it, I made jokes about it.

Waiting a bit and re-thinking my position, I gave it a second chance. It was not easy, there is not too much good introduction material for Vagrant.

Then it dawned to me, that this is could be the holy grail of software development: instantly refreshed development environment. You start to think completely different about setting up environments.

Level 1: Virtualisation

Vagrant creates and manages virtual machines for me. The hypervisor can be configured. Default is VirtualBox. No matter how disturbed your recent experience with this hypervisor is, you’ll like it, now: you do not see anything of it in normal operation. Vagrant completely abstracts/hides the hypervisor.

Other interfaces for other hypervisors exist: some free, like KVM, some commercial like VMware. The costs e.g. for VMware are moderate.

Level 2: Networking

Vagrant manages networking for its virtual machines. Alomost everything is possible: private networking, bridged and NAT. I haven’t really explored the depths of possible configs … not needed, yet.

Level 3: Configuration Automation

Vagrant can deal with many tools for automatic configuration: Ansible, Puppet, even shell-scripts. This allows to very detailed configure the virtual machines prepared by Vagrant.

What you provide to achieve this?

You’ll love that:

  • A vagrant file
  • Some Ansible files

That’s it!

So once you have prepared the files (for this example assuming a single VM):

$ vagrant up

  • Vagrant downloads and caches the VM image specified in the Vagrantfile
  • Vagrant creates the VM from the image
  • Vagrant configures the networking according to the Vagrantfile configuration
  • Vagrant places the SSH key inside the VM
  • Vagrant runs Ansible with the default playbook
    • Ansible installs additional package
    • Ansible patches or installs configuration files
    • Ansible clone the git repo for you

So, assume that with some days of preparation you have created your personally preferred setup for Vagrant and Ansible. Consider you need to switch to a new development hardware (say a Mac, or Linux-machine):

  • Install
    • MacOS
    • homebrew
      • VirtualBox
      • Ansible
      • git
  • Clone your repo

vagrant up

Welcome back in business and that just took about 30 minutes. And all is happily backed up via git in Bitbucket or the repo of your preference. Do this with any other system, you’ll only be able to compete using image backups.

Featured posts