Using Vagrant Plugins

Vagrant is a great tool for those who like to encapsulate their development environment but sometimes it can be annoying and present shortcomings...unless you use its plugins!

Piotr Kurpiewski
Backend Developer

You don't have to worry about breaking compatibility by committing plugin config in your Vagrantfile because you can put it inside a condition so that it will be processed only if the user has the plugin installed. In this article we will show you how to use three plugins that we believe to be very useful.

The Host Updater Plugin

The thing that you have to do with every environment box you are using is find out the hosts used by the application and set them up in your system. Why not to make this automatic? It's as easy as:

$ vagrant plugin install vagrant-hostupdater

Then, in your Vagrantfile file, add the following (assuming domain.loc is the domain you want to add and has api and admin sub-domains):

if Vagrant.has_plugin?("vagrant-hostsupdater")
  config.hostsupdater.aliases = ["domain.loc", "api.domain.loc", "admin.domain.loc"]
end

Now, when you run vagrant up, the listed hosts are being added to your system hosts file, and to keep it clean, once you run vagrant halt or vagrant suspend, the listed hosts will disappear from the file. Great, isn't it?

For more information about this plugin, please visit https://github.com/cogitatio/vagrant-hostsupdater

The Time Zone Plugin

This plugin provides us with an easy way to adjust the box time zone to your own. This is important, especially when working in a team that is spread around the world. It saves you from provisioning or manually modifying the guest system. How many times were you checking the logs and couldn't find what you were searching for because of a different time set in the box you were using? Even if this has never happened to you, it is definitely something that's happened to me and many others.

Let's install it first:

$ vagrant plugin install vagrant-timezone

Now, we add it to our Vagrantfile:

if Vagrant.has_plugin?("vagrant-timezone")
  config.timezone.value = "CET"
end

For more information about this plugin, please visit https://github.com/tmatilai/vagrant-timezone

The Multi Putty Plugin

When using Windows, I prefer to use PuTTy instead of vagrant ssh in the same window. However, to make use of PuTTy’s advantages you have to spend time on converting the key and setting it up. All you need to do with this plugin is install it and use vagrant putty in place of vagrant ssh.

$ vagrant plugin install vagrant-multi-putty
$ vagrant putty

For more information about this plugin, please visit https://github.com/nickryand/vagrant-multi-putty

References

We highly recommend you to visit the vagrant site and also go over the huge list of plugins available on its repository's wiki page https://github.com/hashicorp/vagrant/wiki/Available-Vagrant-Plugins. We're confident you'll find many useful ones for your projects.