Creating Development Environments With Vagrant - Second Edition - Sample Chapter
Creating Development Environments With Vagrant - Second Edition - Sample Chapter
$ 32.99 US
21.99 UK
P U B L I S H I N G
Michael Peacock
Sa
m
pl
C o m m u n i t y
Second Edition
ee
Creating Development
Environments with Vagrant
Fr
E x p e r i e n c e
D i s t i l l e d
Creating Development
Environments with Vagrant
Second Edition
Leverage the power of Vagrant to create and manage virtual
development environments with Puppet, Chef, and VirtualBox
Michael Peacock
), or find
).
I'd like to thank the team at Packt Publishing for their help in getting
this revised edition of the book published, and the technical reviewers
for ensuring technical accuracy in the book.
Creating Development
Environments with Vagrant
Second Edition
Web-based software projects are increasingly complicated, with a range of different
dependencies, requirements, and interlinking components. Swapping between projects,
which require different versions of the same software, becomes troublesome. Getting
team members up and running on new projects becomes time-consuming. Vagrant is a
powerful tool used to create, manage, and work with virtualized development
environments for your projects. By creating a virtual environment for each project,
their dependencies and requirements are isolated, they also don't interfere with the
software installed on your own machine such as WAMP or MAMP. Colleagues can
be up and running on a new project in minutes with a single command. With Vagrant,
we can wipe the slate clean if we break our environment and be back up and running
in no time.
Chapter 8, Creating Your Own Box, discusses the process of creating your own base box
for use within a Vagrant project.
Chapter 9, HashiCorp Atlas, walks you through using Vagrant Share to share SSH and
HTTP(S) access to a Vagrant-managed machine, and how to use the services provided
through the Vagrant Cloud.
Appendix, A Sample LEMP Stack, walks you through the process of creating a LEMP
server within a new Vagrant project.
HashiCorp Atlas
HashiCorp Atlas (https://atlas.hashicorp.com), formerly Vagrant Cloud, is a
suite of online services provided by HashiCorp (the commercial company behind
Vagrant), which adds additional capabilities to Vagrant and brings together many
of their open source components. Primarily, Atlas supports two features:
Vagrant Share: The ability to share access to your Vagrant environment and
to allow others to remotely connect to it
Vagrant box discovery and sharing: The ability to share Vagrant boxes
with others, hosting the metadata for boxes, their versions, and facilitating
box updates
These features are available free of charge, though paying customers can gain access
to additional functionality, including the following:
Box hosting: Vagrant Cloud will actually store the box file on their platform
as well as the metadata
HashiCorp Atlas
Discovering boxes
The Atlas website contains a directory of public boxes for Vagrant (https://atlas.
hashicorp.com/boxes/search). Within this directory, we can search for the specific
operating system or distribution version that we are interested in:
For each result, we can see the box name, which is formatted as the name of the
distributor followed by a slash, followed by the name or distribution name. In the
following case, we have the Ubuntu 12.04 LTS release that HashiCorp has provided
(named hashicorp/precise64):
If we click in a box, we can see which providers the box supports. In this case, we can
use the box with VirtualBox, VMware Fusion, and Hyper-V. It is important to use
boxes that support the provider we are usingnot all boxes support all providers.
[ 112 ]
Chapter 9
The name of the box can either be a URL or file path to an existing box file
(for example, if we have one stored on our network that we wish to use) or
an Atlas box name, like in the preceding command.
This will download the new box; however, we won't see the effect of the new box
unless we destroy our Vagrant machine and rebuild it from the updated box.
If we want to update a specific box, as opposed to the one that is tied to the project
we are in, we can use the box flag to provide the name of the box we want to update:
vagrant box update --box the-box/name
If we omit the global flag, then the command is only within the context of the
current Vagrant project with the flag it relates to all boxes installed:
[ 113 ]
HashiCorp Atlas
Distributing boxes
To distribute boxes with Atlas, we need to create an account and log in to the Atlas
website (https://atlas.hashicorp.com/account/new). The username that we
select when registering is used as the prefix for boxes we distributeunless, of
course, we go onto a paid plan, which has organizational support, or we collaborate
with others on a box. Once logged in, we need to click on the Create Box link to go to
the box creation form (https://atlas.hashicorp.com/boxes/new).
On this page, we need to provide a name and description for our box. As we are on
the free plan, we cannot make this a private box, so it will be made public:
[ 114 ]
Chapter 9
As the boxes distributed through Atlas can be versioned, to let us roll out new
updates to users of the box, we need to create an initial version for the box, along
with a description of what the version contains:
Next, we need to click on Create new provider to add a new provider that is
supported by this version of the box:
[ 115 ]
HashiCorp Atlas
Finally, we specify the provider, and provide a URL to where the box can be
downloaded. With the free version of Atlas, we need to provide a link to the
box, as there is no storage allowance for Vagrant Cloud to host the file for us:
Once a box has been created and published, it can be discovered and installed, as we
discussed in the Discovering boxes section, by the public, or by us using the name of
the box in our Vagrantfile, for example, mkpeacock/testbox.
vagrant connect
vagrant share
vagrant login
[ 116 ]
Chapter 9
As we are not logged in, we need to run vagrant login in order to log in. First, we are
prompted for our username or e-mail address from Atlas, and then for our password:
Once logged in, we can use the logout flag to log out of Atlas:
vagrant login --logout
[ 117 ]
HashiCorp Atlas
Provided we have either given the virtual machine its own network address or
forward a port to a recognizable HTTP(S) port, then we can run the vagrant share
command to create a public URL for this machine. We can also specify the HTTP and
HTTPS ports that we are using on the virtual machine if Vagrant doesn't detect them
with the --http and --https flags:
After running vagrant share, Vagrant will generate a name and URL to access the
share from. As we are on a free plan, we cannot customize or reserve URLs. Our
terminal session is now locked to run this sharing session, so we need to leave this
running. If we visit the URL in a browser, we should be able to see whatever web
service we are running on our virtual machine:
To stop sharing, we need to close the terminal or stop the vagrant share command
from running:
[ 118 ]
Chapter 9
As with a regular share command, we get a URL and a name. We can prevent
HTTP(S) from being shared by passing the --disable-http flag.
[ 119 ]
HashiCorp Atlas
Once the sharing process is running, we can provide the name and password to
whomever we want to be able to connect to the machine. They simply run the
vagrant connect --ssh difficult-elephant-4464 command (where the last
parameter is the name of the connection generated by Atlas) to start a connection
with the machine, and provide the password when prompted:
Summary
In this chapter, we learned about the extra functionality offered by the Vagrant
Cloud service.
We discovered how to find third-party Vagrant boxes for use with our projects, how
to check for updates for boxes that use Atlas, and how to distribute our own base
boxes through Atlas. Finally, we looked at authenticating with Atlas to share our
Vagrant environment with our colleagues.
Now that we know more about the functionality offered by Vagrant, we can use it
effectively in our projects!
[ 120 ]
www.PacktPub.com
Stay Connected: