Vagrant is a popular open-source virtual machine declaration and management tool from HashiCorp. Its popularity comes from the simple Ruby syntax that describes a resource from base image, the resource allocation feature, and other minor provision configurations, such as how it mounts a shared folder or hook provision scripts to prepare the development environment.
It also comes with a variety of providers that can support Vagrant in multiple platforms, with the creation of a local virtual machine on VirtualBox, VMware and Hyper-V.
Additionally, it was extended by the community to support popular hosting services such as Amazon Web Services or DigitalOcean, allowing them to work as providers and abstract all the creation and management process of Droplets and EC2 instances.
This way, developers can simulate and coordinate multiple node architectures through a familiar interface. And the best part? All the specifications are done on a single text file, which can be easily bundled into a project and kept under version control, ready to checkout.
Vagrant offers a fast and clean way of interacting with development environments, using an operating system similar to staging and production. This increases the resilience of applications and makes them less prone to failures that stay hidden on development environments. However, by itself, Vagrant is not the best tool to provision a virtual machine.
Taking this into account, Ansible was our weapon of choice to provision the virtual machines. It doesn’t require any kind of agent running on the virtual machine, as other alternatives such as Chef and Puppet would, and does most of its work through Push, via SSH.
Its specifications are done in YAML, making it quite readable and easy to understand, so that anyone can quickly entail each instruction and change a provision script to suit new needs, such as adding an extra system library for a new gem. The overall structure of the scripts also enables a clear view of the changes being introduced, which helps to entail the new dependencies added during code reviews and security audits. That’s something easy to miss when evaluating a plain shell script with long commands that look like an endless cargo train.
With Vagrant, Ansible’s scripts are just plain text that can be stored with the project, under version code.
Similar to what happens with every other innovation, Vagrant and Ansible's introduction may meet different degrees of resistance on its adoption. Developers that are allocated on just one project for longer periods of time may not fully appreciate this necessity or value its portability, and that’s understandable.
However, as developers hop from project to project, tinkering with different stuff on a daily basis, they will get a better understanding of how valuable Vagrant is. It’s not an uncommon scenario to fix something on an old Python project in the morning, switch to Ruby maintenance in the afternoon and tinker with Node.js in the next day, for instance.
Vagrant efficiently allows changing the project’s context.
Ansible alone is a powerful provisioning tool that effectively interacts with multiple VPS and can be used to deploy changes in large clusters. While a massive usage of Ansible to manage large clusters is not foreseeable in the near future, by adopting it consistently, one can reuse the already built Ansible scripts to setup development virtual machines, provisioning the VPS that will host both staging and production environments.
It's mostly aligned with development best practices, as it builds good and flexible provision scripts that can fulfil more than just provisioning a virtual machine, reusing them when trying to deploy the application to multiple environments.
Whilst Vagrant can be used as a tool to create and manage VPS for development, or even to create staging and production environments, there are other tools that can be used to accomplish the same goals, such as Terraform.
But that's a whole new story for another day...
Found this article interesting? You might like these ones too!
Your everyday web developer who likes to hide in the backend. Javascript and Ruby are my jam. I still fumble with Docker and my builds break quite often.
People who read this post, also found these interesting: