Book Image

Creating Development Environments with Vagrant

By : Michael Peacock
Book Image

Creating Development Environments with Vagrant

By: Michael Peacock

Overview of this book

<p>Vagrant is a tool for building complete development environments. With an easy-to-use workflow and focus on automation, Vagrant lowers development environment setup time, increases development/production parity, and makes the "it works on my machine" excuse a thing of the past.</p> <p>"Creating Development Environments with Vagrant" is a practical, hands-on guide that walks you through the functionality of Vagrant, Puppet, and Chef to create powerful and flexible virtual development environments. Create your own virtualization environments containing configurations for different projects so that you can simulate complicated environments that can be easily shared with colleagues to get your projects up and running quickly and effortlessly.</p> <p>"Creating Development Environments with Vagrant" starts with an introduction to virtualization and the concepts behind it, why it’s useful, and an overview of the architecture of Vagrant. We will learn to install Vagrant and get to know its prerequisites. Covering provisioning scripts with Puppet and Chef, learning to use them independently as well as with Vagrant to create a powerful combination.</p> <p>If you want to locally test your projects, juggle multiple projects running on different versions of software, easily share technology requirement changes with colleagues, and, most importantly, want to perform all these tasks efficiently, then this book is for you.</p> <p>"Creating Development Environments with Vagrant" will take you from a virtualization novice to running all of your projects across your team in robust, isolated virtual development environments.</p>
Table of Contents (15 chapters)
Creating Development Environments with Vagrant
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
Index

Creating the Vagrant project


First, we want to create a new project, so let's create a new folder called lamp_stack and initialize a new precise64 Vagrant project within it by executing the following commands:

mkdir lamp_stack
cd lamp_stack
vagrant init precise64

Tip

You will need to have the Ubuntu precise64 box installed for the previous command to work. For more information, see Chapter 2, Managing Vagrant Boxes and Projects.

We want to forward port 80 from our guest machine to port 8080 on our host machine to make it easier to access the web project we have within the virtual machine. In order to achieve this, let's add the following line to our Vagrant file. Some versions of Vagrant will automatically include this line but commented it out, so we may just need to remove the comment (# character from the start of the line):

config.vm.network :forwarded_port, guest: 80, host: 8080

Before we run our Puppet provisioner to install our LAMP stack, we should instruct Vagrant to run the apt-get update command on the virtual machine. Without this, it isn't always possible to install new packages:

config.vm.provision :shell, :inline => "apt-get update"

As we will be putting our Puppet modules and manifests in a provision folder, we need to configure Vagrant to use the correct folders for our Puppet manifests and modules as well as the default manifest file. Adding the following to our Vagrant file will do this for us:

config.vm.provision :puppet do |puppet|
    puppet.manifests_path = "provision/manifests"
    puppet.module_path = "provision/modules"
    puppet.manifest_file  = "default.pp"
end