Customising Vagrant behaviour

Vagrant is a great piece of software and an integral part of my development toolbox.

One thing that a lot of people don’t realise about Vagrant is that the Vagrantfile which you use to store your configuration in is just Ruby code. This means you can quickly and easily customise the behaviour of Vagrant.

Here are a few quick examples to get you going, place the following snippets in your Vagrant file and then execute a Vagrant command like vagrant up to see their output.

Output the folder path of your Vagrantfile

Output the Vagrant command (up, halt, destroy etc.)

Output all of the Vagrant command line arguments

Output the chosen Vagrant provider

Output the username running Vagrant

As you can see adding these snippets to your Vagrantfile is easy and allows powerful custom logic. You could provision certain resources based on the user running Vagrant or stop people from being able to run commands like vagrant halt, it is very flexible.

One thought on “Customising Vagrant behaviour”

Leave a Reply

Your email address will not be published. Required fields are marked *