Vagrant 101:

What is it and why you should use it?


I am deeply perplexed every time I find out someone working in IT doesn’t know about Vagrant. Especially when this someone is a programmer or an ops. Simply put: Vagrant makes the management of development environments a breeze.

Let’s say you want to start coding on this project you just cloned. Wait, which version of Python should you use? Do you have to install nginx? Oh you need to install these apt package to make it work… 20 min later you give up in frustration and go back on Reddit.

Everything standing between the moment a developer wants to code and the actual coding/testing loop is a productivity killer. Vagrant removes all these roadblocks. One command and you have a full working environment ready to use.

What is Vagrant?


Vagrant is “just” a virtual machines manager. Therefore it does nothing by itself, you need a virtualization software under it (VirtualBox, VMWare, …).

Vagrant simplifies the process of downloading VM images, booting them, stopping them, etc. With one configuration file you can define which operating system you want to use, how much memory, define which IP and ports can be used to access it. You basically describe as code the hardware you want to work on (one of the basic principle of devops).

So you have your VM booted with Vagrant. What now? You can ssh and provision it manually by installing all the softwares you need to run your project. Then make a snapshot of your VM and never have to do the installation step again. Or you can autoprovision it through Vagrant by using a configuration management tool like Ansible, Puppet, etc. (more about these steps in another blog post)

But where is my project code? Vagrant takes care of syncing the folder you want into the VM. So you can still work in local on your files with your favorite IDE and have the changes synced in the VM.

Why you should use it?


Well because it’s awesome. It makes your life easier and your workflow more efficient.

As a developer your productivity when switching projects will explode, you will be more confident about the working state of your code compare to your other environments and your computer setup will be totally decoupled from your projects (buy a new computer, download Vagrant, clone your project, start working like nothing happened).

As an ops no more issues dealing with people distinct development environments, with development environments not matching production or with setting up new employees computers, ssh environments and whatnot.

As a devops… well… You should already know Vagrant. If not, shame on you.

Use cases


I think the best way to grasp the potential benefits of anything is to relate it to common use cases. So let’s go over a few you might have already encountered.

New employee setup


Someone just join your team. He has his brand new macbook and is ready to code! Hold on. First he needs to install the whole stack. Best case, you have a wiki with all the steps and commands to run. Worst case, you sit with him, try to remember what to install, what versions, where, how. 2 days later your new employee is setup.

Meanwhile at your concurrent’s office, a new employee joined the team. He got his macbook, downloaded VirtualBox and vagrant. Cloned the project, ran “vagrant up”, was ready to work in 15 minutes.

Switch between projects


I have 3 active side projects right now. One full of Python scripts interacting with a website in Rails, one in Rust and one in C++. Switching contexts take me 10 seconds. I cd to a project folder, run “vagrant up” and I am 100% sure I have an up-to-date, fully working stack in less than 1 minutes for any project I want to work on.

But it works on my machine!


You coded your new feature, tested it and pushed your code. And… it does not work in production. You ask your colleagues if they can reproduce the issue. Half of them can, the other half cannot. Everybody is using a different os and/or development environment. And no one is close to look like production. It’s a mess, I even feel bad writing about it.

With Vagrant your team works on a controlled setup. Everybody has the same environment. Which should be as close as possible as the one in production (thanks to a configuration management tool!).

Conclusion


Vagrant will drastically improve your life. A bonus point as a developer is that you will learn a lot about sys. administration, about the whole stack of your application and become so much better at not just thinking about coding but also about the whole ecosystem you’re working on. What? No I didn’t say devops! But we’re getting there!

Next


Vagrant 102: Basic VM creation and manual provisioning coming soon!

Email me when Vincent Marger publishes or recommends stories