Using Salt Stack and Vagrant for Drupal Development

What if, just like Bill Murray in Groundhog Day, you could wake up to a fresh and identical development environment completely free of yesterday's experiments and mistakes? Vagrant lets you do exactly that.

Or, what if, like Jake Epping in Stephen King's 11/22/63, you could make changes and script the past without fear, play around with some new Drupal modules, and quickly reset everything just by leaving and then walking back down the stairs of the pantry again?

Would you like to automate the creation and installation of a pristine Drupal environment, instead of manually installing Apache, PHP and all of the needed libraries?

Recently, I read a post from Treehouse Agency titled, "End 'Works on My Machine' Surprises with Vagrant", which is about using Vagrant and Puppet for Drupal development. You may have seen it as well on Drupal Planet and wondered about the benefits described there.

This is a great technique that outlines using various tools to build a consistent development environment quickly that is repeatable and shareable with everyone on your team.

Linux Journal also recently featured an article that introduced Vagrant. After you're finished here, I urge you to go read that one too, because it offers more general information about Vagrant itself.

Salt Stack is a tool similar to Puppet, but it's powered by Python, instead of Ruby. If you are interested in standalone Salt installation and use, check out my November 2012 LJ article on that topic, where I introduce Salt Stack and show how to install it to control one or thousands of other machines. I won't go in depth into Salt's installation here, because Salty-Vagrant takes care of all of that for you.

I've been using Salt, Vagrant and a Vagrant gem called Salty-Vagrant for Drupal development quite a bit lately. I've found that having a standard configuration that mirrors my development, testing, staging and production environments has streamlined my workflow and helped prevent a lot of the unknowns between different stages of the Drupal development life cycle. I've been able to minimize a lot of the errors and headaches that come with integrating multiple software stacks and speed up my workflow too.

I also enjoy being able to try new things quickly and easily without spending hours reconfiguring and re-installing the entire software stack needed for Drupal development.

I then can share these configurations quickly and easily with other developers on my team and know that we are each working with the same versions of software already installed. In this article, I describe how you can do that too.

With Salt Stack, you store your configurations in text files, similar to Puppet. The difference is that the configurations rely on YAML templates instead of Ruby code. This makes them easy for humans to read, even if they aren't Python coders.

These configurations can be used to launch development machines, as well as testing, staging and production machines—and all of them are identical and easily transportable. I use Git to manage my team's configurations. This brings all of the great aspects of version control to my server configurations too.

With Vagrant, you easily can delete a development environment and then re-create it in about as much time as it takes for the server to boot and install the packages and software you specify—kind of like a quick undo or reset button.

Getting Started

You need to download and install a few things to get all of these pieces to work together. Each component has very good documentation on-line for installation and use, so I won't duplicate the instructions here. Instead, follow the links for each piece of software and check the projects' sites for the most up-to-date information.

This article focuses on using an Ubuntu-based 64-bit VirtualBox, but Salty-Vagrant with Salt Stack supports BSD, Red Hat, OS X and Windows virtual machines as well.

The beauty of using Vagrant with Salty-Vagrant is that the configuration files, also known as SLS files, transfer exactly to production servers, as well as anywhere else you might use them. The benefit of creating one template and then re-using it again and again can help you direct more energy toward Drupal development, instead of troubleshooting server-software installation too.

You need to do this installation and configuration only once. After that, it is as simple as vagrant up!

Install VirtualBox

VirtualBox allows you to run a guest operating system inside your own host operating system. It is similar to dual-booting, except you still can use your main operating system and have access to additional running operating systems as well. For example, you can run an Ubuntu server inside your Windows, Mac or Linux host operating system and still access your e-mail and text editor from your native host operating system.

Follow the instructions at http://virtualbox.org to install VirtualBox. Versions are available for most major operating systems. A major portion of popular Linux distributions also have packages available through their respective package managers. This is the most effective and efficient way to install the majority of tools I describe here.

Install Vagrant

Vagrant is a Ruby gem that allows you to create and destroy virtual machines quickly, and then reset them almost instantly.

Gems are like Drupal modules, but for the Ruby programming language. These plugins let you extend Ruby's functionality and add additional capabilities. You should ensure that you have a recent version of Ruby installed. I recommend using your package manager if you don't have it, but a lot of distributions include Ruby already, so you likely won't need to install it. You easily can find out whether you have Ruby installed by typing ruby --version from your terminal.

Install Salty-Vagrant

Salty-Vagrant is another Ruby gem that brings the functionality and automated configuration tools of Salt Stack to Vagrant. Salty-Vagrant acts as a bridge between the Salt Stack configuration management system and Vagrant/VirtualBox. The project's page has installation instructions that are updated on a regular basis. It would be a good idea to refer to these instructions just in case something has changed after this article is published. If you know a little Ruby or shell scripting, feel free to join in this open-source project and help contribute back. You'll find the development community to be friendly and welcoming.

______________________

Ben Hosmer is a DEVOP with RadiantBlue Technologies where he develops and maintains Drupal sites and administers various servers. He is an open-source advocate and helps spread the use of Linux and other open-source software within the US government.

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Network type VM setting should be updated...

Cruz's picture

Thanks for the great tutorial!!

I'm currently using Vagrant version 1.2.4 and it did not like the "hostonly" Network type: Network type 'hostonly' is invalid. Please use a valid network type.

I looked up the online Vagrant docs and found that the correct Network type is: "private_network"

The above VM setting should change...
From:
config.vm.network :hostonly, "192.168.33.19"
To:
config.vm.network :private_network, "192.168.33.19"

Thanks again!!

info

Anonymous's picture

I am very happy to discover this particular post very beneficial personally, as it includes lots of details. I choose to browse the quality articles which issue I ran across in your soul post. Appreciate your expressing!
Learn 2 Backlinks for Seo

Everything is well designed

zeennate's picture

Everything is well designed your site and very nice with many choices, it is a wonder! Congratulations. friendly
voyance gratuitement

use Vagrant

Propeople's picture

Also check out this article about how Vagrant can help you simplify a complex development environment. http://wearepropeople.com/blog/complex-development-environment-simplifie...

Question about a step

Bruno Barrette's picture

Hi,

First of all, thanks for the article... Currently trying to set this up for some testing, it looks more than interesting.

I have a question though for something that seems to be missing some informaiton...

In the step "Add a Salty-Vagrant-Specific Vagrantfile":

When you're talking about deleting the vagrantfile we already have, just to make sure, you're talking about the one in the salty-vagrant folder, right?

Afterwards, you are redirecting us to take the Vagrantfile from the given URL... What Vagrantfile config should we take? There is a sample one on that page, that doesn't seem to reflect the next directions you give in this tutorial (there is no minion_conf line in this example). There is also one in the exemple folder, should it be this one?

I am up to this point now, hopefully you can provide a clarification on this step.

Thanks in advance,
Bruno

Reply to comment | Linux Journal

aesthetic dentistry nyc's picture

My family always say that I am killing my time here at net, but I know I am getting knowledge all the time
by reading such nice articles or reviews.

Reply to comment | Linux Journal

tmobilecustomerservicenumber.com's picture

Amazing! This blog looks exactly like my old one! It's on a completely different subject but it has pretty much the same layout and design. Wonderful choice of colors!

Have you tried Boxen? It's a

Adam Gerthel's picture

Have you tried Boxen? It's a dev toolkit made by Github in order to easily set up dev environments, and it uses Puppet. It solves the same problem in a way that Vagrant does, but made for OSX.

Please correct the URL for Salt Stack's web site

Anonymous's picture

The article text has a URL for Salt Stack with a typo. Please change it to http://saltstack.com/community.html and delete this comment.

Automatically updating Guest Additions

Bert VV's picture

Nice article, thanks for sharing. Especially the part about Salt is interesting.

There's a Vagrant plugin that can automatically update VirtualBox Guest Additions: https://github.com/dotless-de/vagrant-vbguest

Every time you boot a box, it checks the version and updates when necessary.

Cheers,
bert

Reply to comment | Linux Journal

what to say to beautiful women's picture

Great article! We are linking to this particularly great post on our site.
Keep up the great writing.

Reply to comment | Linux Journal

Samantha's picture

I'm not sure why but this site is loading extremely slow for me. Is anyone else having this issue or is it a issue on my end? I'll check back lateг
аnd sеe if the pгoblem ѕtill ехists.

Webinar
One Click, Universal Protection: Implementing Centralized Security Policies on Linux Systems

As Linux continues to play an ever increasing role in corporate data centers and institutions, ensuring the integrity and protection of these systems must be a priority. With 60% of the world's websites and an increasing share of organization's mission-critical workloads running on Linux, failing to stop malware and other advanced threats on Linux can increasingly impact an organization's reputation and bottom line.

Learn More

Sponsored by Bit9

Webinar
Linux Backup and Recovery Webinar

Most companies incorporate backup procedures for critical data, which can be restored quickly if a loss occurs. However, fewer companies are prepared for catastrophic system failures, in which they lose all data, the entire operating system, applications, settings, patches and more, reducing their system(s) to “bare metal.” After all, before data can be restored to a system, there must be a system to restore it to.

In this one hour webinar, learn how to enhance your existing backup strategies for better disaster recovery preparedness using Storix System Backup Administrator (SBAdmin), a highly flexible bare-metal recovery solution for UNIX and Linux systems.

Learn More

Sponsored by Storix