Get Started With Vagrant

The second most quoted saying in enterprise IT must be “well, it works on my machine” only to be slightly edged out by “it must be the network” and honestly, doesn’t it always feel like it’s the network (insert smile and laugh). Traditional development environments are set up manually, which over time can cause production and development to get out of sync.

The configuration of those environments also presents a challenge, misconfigured software can give the impression that the software is working in development but when moved to production, well things start to break down. You want production to be a match with development.

One tool that can help your development teams is Vagrant from HashiCorp.

There is so much power in the command-line

Vagrant is a tool for working with virtual environments, more specifically virtual machines. Vagrant is also open source, which means you can modify and share it. If you enjoy using the command-line, then this will become a go-to app for you and the team.

Think of Vagrant as a tool for building a development environment right on your own machine, whether its Windows, Linux or MacOS. Using the Vagrant command you can do many of the following:

Developers can pull a Vagrant box from the online repository, run vagrant up, and have a fully running development environment without any enterprise IT support. This can help keep the environments consistent and easy to deploy – Consider this, a use case where you have Git running and your developers are asked to pull down boxes from that repository. Can you start to see the benefits.

One of the cool things is that if something goes wrong, or you want to start over from a clean environment, developers and operations can run vagrant destroy, which removes all traces of that development environment from their machines. Then they can redeploy a new working environment to their workstation in minutes.

Build our first machine with Vagrant

I’ve installed Virtualbox 5.2, Vagrant 2.1.2 and will go through the steps to build a virtual machine. Vagrant supports out of the box VirtualBox, Hyper-V, and Docker, you can work with other machines in which you would use different providers. VMware providers are suggested if you are going to use this with VMware Workstation or Fusion, as an example.

Once installed type vagrant –version to ensure its all installed correctly.

Screenshot remove – to be updated

Now that Vagrant is installed, let’s create a local directory for our project. I called my projects/vagrant (I know it’s not the most creative, I’ll do better next time). Change directories to that local folder and run the vagrant init ubuntu/trusty64 command.

Screenshot remove – to be updated

This will initialize the current directory to be a Vagrant environment and placing the Vagrantfile in that directory. In case you are wondering what the ubuntu/trusty64 is, well that’s the box that Vagrant will be using in our case, it’s an official ubuntu 14.04 build.

The primary function of the Vagrantfile is to describe the type of machine required for a project, and how to configure and provision these machines.

Vagrant is meant to run with one Vagrantfile per project, and the Vagrantfile is supposed to be committed to version control. This allows other developers involved in the project to check out the code, run vagrant up, and be on their way. Vagrantfiles are portable across every platform Vagrant supports.

Next, you type vagrant up and that will cause Vagrant will check if that box exists on your local machine, if it doesn’t it will download a copy from the Vagrant Cloud (Think of this as a box repository).

Screenshot remove – to be updated

Now, with the ubuntu/trusty64 VM up and running, if you run vagrant ssh that will take you directly into that VM and this is where you can begin to install software, configure the system, etc. When you are done, just type exit and you are back to your prompt.

Screenshot remove – to be updated

Finally, if you are done with this machine or need to start over for whatever reason, run the vagrant destroy command and the VM along with any metadata.

Screenshot remove – to be updated

There is so much more we could cover, but I wanted to give you enough information to spark your interest in trying out Vagrant and simple steps on getting started as fast as possible.

To learn more about Vagrant check out their website and documentation page. You can also find some insightful videos on YouTube.

Have you used vagrant in the past? Do you run vagrant at scale within an IT enterprise? Let me know on Twitter and as always, thanks for reading.