Book Image

Vagrant Virtual Development Environment Cookbook

Book Image

Vagrant Virtual Development Environment Cookbook

Overview of this book

Table of Contents (17 chapters)
Vagrant Virtual Development Environment Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Finding additional Vagrant boxes


Up to this point, we have provisioned Vagrant environments using a single box—a version of Ubuntu 14.04 LTS (Trusty Tahr) provided by PuppetLabs, a company that sponsors the open source Puppet configuration management software as well as commercial Puppet products. (We'll see how to use Puppet with Vagrant in later recipes.) There are two reasons why we used this box in the examples:

  • PuppetLabs packaged Ubuntu 14.04 boxes for a few different hypervisors (VirtualBox and VMware).

  • PuppetLabs, as a company, offered a relatively stable set of boxes to develop Puppet. These should be broadly available after the publication of this book.

Most users will likely want to use Vagrant boxes that reflect the eventual production deployment environment of the code being developed inside Vagrant boxes and not just the single distribution we've seen so far.

To use different operating systems and operating environments, we need to obtain (or create) different Vagrant boxes. A Vagrant box is a packaged virtual machine that consists of a virtual machine image (a set of VMDK files for VMware, OVF files for VirtualBox) and a metadata file that specifies (at minimum) the provider that the box file uses along with other information that box users might need. Several Vagrant workflows use a base box along with provisioning to create new development environments, where the base box is the operating system that is eventually used in a production environment. For example, if a production environment has standardized on CentOS 6.5 as an operating system to host a web application, developers can use a Cent OS 6.5 Vagrant box as a development environment, ensuring that the web server versions and configurations are identical between environments.

There are many cases where you will want to build an environment, but in this example, we'll take a look at finding Vagrant boxes on the Vagrant Cloud (http://vagrantcloud.com).

Getting ready

Vagrant Cloud is an offering from HashiCorp to use and share Vagrant environments. Vagrant Cloud allows box providers and other users the ability to publish and share Vagrant boxes with other users. In many cases, these shared boxes will have certain software preinstalled for your use, and in other cases, the boxes will be basic operating system installations for you to provision and configure.

The navigation option DISCOVER BOXES on the top menu will take you to a repository (https://vagrantcloud.com/discover) for you to search for boxes and view information about box versions and what might be installed.

Note

A note on types of boxes

In this example, we will be downloading and using 64-bit Vagrant boxes, which might cause problems with some environments. In particular, 64-bit guests require systems to have Intel processors that support Intel Virtualization Technology (Intel VT) and have Intel VT support enabled in the BIOS settings of the host operating system. If you are unsure of the support available for your platform, there is a useful article on the VMware Knowledge Base with some tools to test the ability of your desktop system to support 64-bit guests. The article can be found here:

http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=1003944

How to do it...

HashiCorp provides a repository of box files that can be downloaded for use in the Vagrant Cloud repository. At the time of writing this book, HashiCorp is also migrating the Vagrant Cloud repository to the new Atlas platform. While Atlas might have additional features, HashiCorp has committed to keeping the Vagrant Cloud features free to the community, including the box repository.

Finding boxes

Within the Vagrant Cloud box repository, we can search for boxes based on providers, operating systems, or software packages installed. At the time of writing this book, the Ubuntu 14.04 LTS release (Trusty Tahr) is starting to come into more widespread use a few months after release. As an example, let's find a basic installation of Ubuntu 14.04 to use in our environment.

  1. On the box repository page (https://vagrantcloud.com/discover), enter the search term ubuntu 14.04. You'll notice that by default, the discovery page displays a list of featured boxes—these are boxes that are popular or noted by the community as being of high quality or useful for a wide variety of environments. In our case, the Ubuntu release has not been published as a featured environment as of yet.

    Once the search term has been entered, the repository allows you to filter search results; this is useful if you are looking for a specific desktop version (for example, VirtualBox or VMware).

    Another item you might wish to note about the search results is that the repository also follows the naming convention for box naming of box creator or box name. Looking through the search results for ubuntu 14.04 and using the virtualbox filter, you'll find a box called ubuntu/trusty64. This box was created by the Ubuntu project itself and is fairly popular. At the time of writing this book, it has been downloaded over 200,000 times.

  2. The box name is a link to a page, which displays some detail about the box. The box providers might publish some further information about the box and how it can be used. There is also a stanza that can be copied and used to initialize a new environment.

Now that we have found a box to use, there are a few ways that we can use this box in our environment.

Initializing an environment with a new box:

Initializing an environment with our new box is identical to how we initialized our first environment in the previous recipe. In this case, we can even copy the line presented in the detailed description of the box in the Vagrant Cloud repository. In this example, copy the vagrant init ubuntu/trusty64 line into a new terminal window. This will generate a Vagrantfile with the config.vm.box = "ubuntu/trusty64" box definition.

As before, a simple vagrant up command will prompt Vagrant to download the box (if it has not been previously downloaded) and boot a new virtual machine instance. We now have an environment to begin provisioning and configuring.

Adding a new box without initializing an environment:

The other option to use a new box is to simply add the box to our local Vagrant cache for later use in Vagrantfile definitions.

Vagrant maintains a local cache of downloaded boxes for later use. New environments will simply copy the base image to boot new environments from the cache, rather than triggering downloads every time Vagrant is initialized. This is particularly handy when developing system configurations; destroying and rebuilding boxes will copy and provision clean images without requiring users to be concerned about maintaining snapshots, copies, or other artifacts of the virtual machine environment itself.

To cache a box for later use, execute this command in a terminal window:

vagrant box add ubuntu/trusty64

In this case, we're using the vagrant box command to manage our box cache. Using the add command will trigger the download of the box from the Vagrant Cloud repository to the local cache. With the box cached locally, we can use it later to initialize new environments without triggering a download. (As you might suspect, you can also clean up your cache by using the vagrant box remove command, or see a list of the boxes present in the cache along with the provider information about the box by using the vagrant box list command.)

There's more...

While there are several boxes to discover and use on the Vagrant Cloud, you might also encounter situations where there are different boxes or repositories used for Vagrant projects. In these cases, you can specify an HTTP URL to the vagrant box commands to cache boxes for later use. For example, a frequent case might be development teams sharing custom boxes on an internal server. In this case, adding the box would use the URL of the box file itself, as such:

vagrant box add http://servername/boxes/environment.box

Assuming the example here, servername represents a known web server address with a box called environment.box served from the boxes path on the web server. In this way, teams can share and use box files without requiring the use of the Vagrant Cloud service, or sharing Vagrant boxes using source control.