So now that we have a general overview of what the hell Vagrant is and why you should be using it, there are a few bits that need to be explained before we can dive in and start creating local projects.
Boxes are at the core of Vagrant. They are a self contained operating system held within a file. They are not actually part of Vagrant, but VirtualBox, however the team behind Vagrant have been so kind as to make a central repository of Boxes that can be downloaded at vagrantbox.es. While you can download the boxes and store them on your computer, you can also just copy the URL and add it to your configuration file, so Vagrant will download and store it when it is creating your project. There are hundreds of boxes on vagrantbox.es, so incase you’re not sure which to pick, the “Ubuntu precise 32 VirtualBox” is a good starting point.
At its core, Vagrant is pretty simple, you have a handful of commands to create (up), restart (reload), access (ssh), suspend (suspend), switch off (halt) and delete (destroy). The rest is done from the configuration file and through the Chef or Puppet provisioning.
So if we have a box ready to be made active with a configuration file in place, all we would do is write the following:
Vagrant would then run through the ‘Vagrantfile’ configuration and download the required box file if it not already stored on your computer. Then, once it has asked VirtualBox to start the Guest OS, you can access the box via the ‘ssh’ command:
This will then create a secure shell connection to the operating system which is sitting, idle, on your dev machine. Why should you want to access the Guest OS via SSH? Well, when you have connected to the Guest OS, you can do anything you might do to a server sitting on the internet somewhere, install software, access logs, create users, etc etc etc…
Its important to remember that the Guest OS is a fully functioning operating system which is, most likely, a full Linux install, ready and waiting for commands.
To quit the connection, just type “exit”.
So, we have a box we can connect with, to restart the Guest OS, type:
To suspend the OS in its current state, saving whats in memory and allowing for a quick boot up time when its reloaded next, use the following:
If you wanted to shut down the OS to wipe whats in memory and make sure it starts up clean next time:
And finally, if you wanted to delete your Guest OS, not the box its self, just the current project that Vagrant created for you when you typed “vagrant up”, then you would type:
Vagrant is really simple, hiding all of the work its doing behind a few specific and very useful functions. Next we’ll move on to Getting started using Vagrant and understanding the configuration file.