Your own Vagrant Cloud.

Jon Ursenbach
2 min readAug 4, 2014

--

A how-to guide for setting up your own private Vagrant Cloud.

Update (8/20/15): This article is most likely very out of date now since Hashicorp moved Vagrant Cloud into their Atlas

Since HashiCorp announced that their Vagrant cloud offering was out of beta, I’ve been curious if you could hack an instance of Vagrant Cloud on your own servers. Vagrant Cloud is a great service though, so why would you want to run your own instance? A couple of reasons: saving money and privacy.

If your organization wants to host private boxes with unlimited collaborators, it may be a lot cheaper for you to spin up a box in your datacenter than it is to pay $5/user.

And the lesser case of privacy. Depending on what you are putting into your base boxes, you might not be willing to hand that over to another company for safe keeping. Though you shouldn’t really be putting confidential data into base boxes, and instead provisioning that in later, but who knows what your situation and setup is.

So how can you set up your own instance?

The Server

In order to serve Vagrant boxes with a short name, like “myorg/mybox”, you need to set up a server on a domain of yours. The folder schema for the domain you’re serving boxes from has to be the following:

https://gist.github.com/jonursenbach/f4cfd087199030eecefb

The important file of note here is mybox.json. This is the file that tells Vagrant where to pull your box from. The syntax for this file is as such:

https://gist.github.com/jonursenbach/5f5fb58929a49379d2b9

As you can see, we’re telling Vagrant where our v1.0.0 myorg/mybox is located. If you need to make revisions to your box, you can even utilize box version constraints by adding more objects into the versions array and incrementing the version directory number.

For an example of this in action, check out the live JSON file for hashicorp/precise64.

The Vagrantfile

Now that you have a domain and server set up, how do you actually use this in your Vagrantfile?

ENV[‘VAGRANT_SERVER_URL’] = ‘https://my.customcloud/'

Add that to the top of your Vagrantfile, make sure “config.vm.box” is set to “myorg/mybox”, and you’re good to go!

Drawbacks

There are some drawbacks to this of course. Box management commands like “vagrant box update” don’t work with this model. Things like “vagrant box add” should work if you have VAGRANT_SERVER_URL set in your environment, but you can’t expect everybody on your team to have that set.

The upside to “vagrant box add” not working is that you can still do “vagrant box init mycorp/mybox”. Once you get a fresh Vagrantfile with your shorthanded box name, you can then add in the environment variable to retreive it off your server on “vagrant up”.

Would I recommend setting up your own Vagrant Cloud instance? Not particularly since this is a super dirty hack, but maybe? It really comes down to your situation, how much willing you’re willing to (not) spend with HashiCorp, and if you can do without built-in tools for box management and discovery.

At the very least, it’s neat to see how simple services can be to be extremely useful.

--

--