Vagrant and Puppet, Part 2: Vagrant Up!

Vagrant

In Part 1 we downloaded and install VirtualBox and Vagrant. In this article we’ll create the virtual machine and SSH into it.

Step 1: Create the Vagrantfile

Inside your project folder create a text file named Vagrantfile, there is no extension. This is the file that Vagrant will read to provision the virtual machine.

Open the file in an editor and add the following code.

You might notice this is in Ruby syntax. Don’t worry if you are unfamiliar with Ruby, you will not really need to know any.

Line 1 opens the configuration block and tells Vagrant that we want to use version 2.

Line 2 declares what operating system we want  our virtual machine to use. This particular example is for a Ubuntu 14.04 64-bit base box that HashiCorp, the company behind Vagrant, hosts.

Vagrantbox.es has a good list of all the base boxes available to use.

Line 3 sets a static IP for the virtual machine. This line is optional but one I always take since I use Vagrant to set up servers.

Live 4 sets the machine’s hostname.

Line 5 ends our configuration block.

Save the file and close your editor. This is all we’re doing with the Vagrantfile today but if you’re interested in learning more check out the documentation on Vagrant’s website.

Step 2: Starting the Vagrant Box

Open a terminal or command-line window and navigate to your project directory.

Type and enter the command vagrant up.

At this point Vagrant will download the base box then setup and boot the virtual machine. If it finishes successfully you’ll see a line that says, “Process finished with exit code 0.” Your machine is now ready to use.

Step 3: SSH into the Vagrant Box

Using SSH to connect to your new virtual machine is just as easy as starting it. In your command-line type vagrant sshand wait until it logs you in. From here you’re in a full have access to the shell of your virtual machine. When you’re ready to log out just type exit.

If you’re on a Windows machine you might get a message that you do not have a SSH client installed. You will need to find and install a client.

Step 4: Stopping and Deleting the Vagrant Box

To shutdown the virtual machine just use the command vagrant halt in the Vagrantfile’s directory using the command-line.

If you want want to completely delete the machine, say if you’re finished with the project and want to recover hard driver space use the vagrant destroy command.

That is it for this article. In Part 3 we’ll start using Puppet to further configure the VM.

Leave a Reply