Vagrant is pretty cool to spin up development enviroments. But sometimes it annoys me. Every so often I would end up with a filled harddrive with old boxes, and the only way you could remove those was removing them one by one.
That is no fun…
In my search for a solution i found an old Github issue which asked for specifically a way to remove old boxes. I thought by myself, ‘it can’t be that hard to make’, so I started reading up on how to create a vagrant plugin.
Develop and publish
Creating a development environment for Vagrant wasn’t too hard. Just use RVM to get a working Ruby installation, clone the repository and after installing the bundle you’re good to go.
It was quite a lot of fun doing some Ruby. It did feel a bit weird asking myself question like ‘how would a hash-map work in Ruby’ and looking for basic stuff like that. Getting it to work wasn’t really that hard thankfully. I even looked into how to write tests and get those up and running, fun stuff!
The thing with Vagrant is, everything it does is a plugin internally, which made it quite easy to extract a Vagrant plugin from the pull request. And i’m glad i did, the PR hasn’t been merged yet, and it might be taking a while. Sigh…
It was a fun journey, learning a bit of Ruby, learning how to publish gems, and seeing a decent amount of installs on it.
So now we have a awesome plugin with the not so awesome name “Vagrant remove old box versions“. Pretty easy to use really.
$ vagrant plugin install vagrant-remove-old-box-versions $ vagrant remove-old-versions --help Usage: vagrant remove-old-versions [options] Options: -p, --provider PROVIDER The specific provider type for the boxes to destroy. -n, --dry-run Only print the boxes that would be removed. --name NAME The specific box name to destroy. -f, --force Destroy without confirmation even when box is in use. $ vagrant remove-old-versions
Have fun 🙂