Use Vagrant, packer and puppet to automate the creation of development environments (Part 1)

This is the first part in a series of posts about Vagrant, Packer and Puppet and how you could use them to automate (and simplify) the creation and distribution of development environments.

First of all I should give a quick description of what Vagrant, Packer and Puppet is. According to their websites, Vagrant is a tool to “Create and configure lightweight, reproducible, and portable development environments“. Packer is a tool to “…creating identical machine images for multiple platforms from a single source configuration“. Puppet is a tool to automate IT by “ a configuration management system that allows you to define the state of your IT infrastructure, then automatically enforces the correct state…Puppet automates tasks that sysadmins often do manually…“. Hopefully this has given you an idea of what these tools are. Feel free to visit their respective websites to read more, and then come back to continue reading the post.

So, now that you know what these tools are, you are probably wondering why you should use them. To answer that question we need to think the current state in development environments. How do web developers develop their software? Usually they download and install the needed software in their pc, or laptop, and configure them to their liking. So for example if a LAMP stack was needed one would either install XAMPP or manually install Apache, PHP, MySQL etc. While not a trivial task it certainly needs to be done manually. Now imagine a situation where there are 15 web developers working on a huge project that has a lot of dependencies, and each web developer is working on a different OS. Now you do have a problem. Imagine all the time spent manually setting up each development environment. In addition, due to different configuration, the code that is running on one linux machine might not run on a windows machine. What’s more, your production server might run on a different configuration so you do have that additional problem. While not very common, a web developer might not have the system administration skills to set up and properly configure his system. If you have tried to set up a Ruby on Rails development environment, you sure know what I am talking about…

This is the kind of problems that Vagrant (with Puppet) are trying to solve. While both are relatively new tools they are very popular and widely used. That is a sign of a real problem finding its solution. Vagrant is essentially using Virtualbox (other providers are supported) to automate the creation and management of virtual machines for you. With a simple command, vagrant up, you have your development environment ready. I already mentioned Virtualbox, but Vagrant supports other virtualization software like VMWARE, KVM, and cloud infrastructures like OpenStack, Amazon and DigitalOcean. In Vagrant terminology these are called Providers. Provisioners, are the tools like Puppet or Chef (and others) that actually download, install and configure the software. So, in the example above, Puppet is the tool that would download, install and configure Apache, PHP and mySQL (among others) to set up a LAMP stack for you. Now that is a level of automation that really matters. Have a development environment build up for you automatically. Granted, you would have to write the configuration for that to happen, but its a one time think. And you have a LAMP stack environment for ever. How amazing is that?

And with that, we came to the end of Part 1. In this post I wanted to introduce the tools and give a simple explanation of what they do. I also wanted to pinpoint the problem with the way we create development environments today, and how we can use these tools to solve this problem. Of course we just scratched the surface. In Part 2, we will dive in and create our own virtual machine in VirtualBox, and package our virtual machine to a vagrant box. In a later post we will use Packer, to completely automate this process! If you have any questions or suggestions please use the comments below. Stay tuned for Part 2!

Click the link to go straight to the second post.