Painless WordPress Dev Environments with Vagrant and Ansible

26
Painless WordPress Development Environments with Vagrant and Ansible October 7, 2014

description

How to use VirtualBox, Vagrant and Ansible to bootstrap ready-to-use WordPress development environments in seconds.

Transcript of Painless WordPress Dev Environments with Vagrant and Ansible

Page 1: Painless WordPress Dev Environments with Vagrant and Ansible

Painless WordPress Development Environments with Vagrant and Ansible

October 7, 2014

Page 2: Painless WordPress Dev Environments with Vagrant and Ansible

You need a server

Page 3: Painless WordPress Dev Environments with Vagrant and Ansible

Rogue Repairman Productions | Alexandria, VA | [email protected] | 703-542-4025

The Problem

● If you're building Web applications, you can't do your work without a server

● But where should that server be?● In other words, where should you be doing your work?

Page 4: Painless WordPress Dev Environments with Vagrant and Ansible

Rogue Repairman Productions | Alexandria, VA | [email protected] | 703-542-4025

Making Do

● PHP's built-in web server?● Installing everything locally?● WAMP?● Staging server?● Directly on the production server?

Page 5: Painless WordPress Dev Environments with Vagrant and Ansible

“There's got to be a better way!”

Page 6: Painless WordPress Dev Environments with Vagrant and Ansible

Rogue Repairman Productions | Alexandria, VA | [email protected] | 703-542-4025

What Makes A Good Dev Environment?

A good development environment should be...● Private● Homogeneous● Repeatable● Easy

Page 7: Painless WordPress Dev Environments with Vagrant and Ansible

Rogue Repairman Productions | Alexandria, VA | [email protected] | 703-542-4025

A Better Way

Page 8: Painless WordPress Dev Environments with Vagrant and Ansible

Rogue Repairman Productions | Alexandria, VA | [email protected] | 703-542-4025

Three Tools

● VirtualBox: virtualization software● Vagrant: encapsulates virtual environments● Ansible: easy configuration management

Page 9: Painless WordPress Dev Environments with Vagrant and Ansible

Rogue Repairman Productions | Alexandria, VA | [email protected] | 703-542-4025

Lock-in? Nah

These tools don't just work with each other – others can be swapped in where appropriate

● VMWare, Docker, Amazon EC2● Real hardware, EC2, commodity VPSes● Chef, Puppet, Salt

Page 10: Painless WordPress Dev Environments with Vagrant and Ansible

Rogue Repairman Productions | Alexandria, VA | [email protected] | 703-542-4025

So Why Choose These Three Tools?

They offer an appealing combination of:● Power● Desktop utility● Ease of use

Page 11: Painless WordPress Dev Environments with Vagrant and Ansible

Rogue Repairman Productions | Alexandria, VA | [email protected] | 703-542-4025

VirtualBox

What is it? General-purpose virtualization software

● Can guest anything that runs on x86/AMD64: Windows, OS X, Linux, BeOS, MS-DOS, OS/2...

● Can host on Linux, Windows, OS X, or Solaris

Page 12: Painless WordPress Dev Environments with Vagrant and Ansible

Rogue Repairman Productions | Alexandria, VA | [email protected] | 703-542-4025

VirtualBox

Page 13: Painless WordPress Dev Environments with Vagrant and Ansible

Rogue Repairman Productions | Alexandria, VA | [email protected] | 703-542-4025

Vagrant

What is it? A tool for encapsulating virtual environments

● Specify standard configurations for virtual machines...

● … then use Vagrant to bundle them all up in a clean, ready to go state

● Then you can roll out new instances of them just by copying a few text files

Page 14: Painless WordPress Dev Environments with Vagrant and Ansible

Rogue Repairman Productions | Alexandria, VA | [email protected] | 703-542-4025

Ansible

What is it? A tool for orchestrating machine configurations

● Create and run recipes that take you from bare OS to fully configured system

● Install software● Change configuration files● Create, modify and remove users and

permissions● Do anything you can do from the command line

Page 15: Painless WordPress Dev Environments with Vagrant and Ansible

Let's get to work

Page 16: Painless WordPress Dev Environments with Vagrant and Ansible

Rogue Repairman Productions | Alexandria, VA | [email protected] | 703-542-4025

Step 1: The “Base Box”

● A packaged-up VirtualBox VM with operating system (and sometimes other software) already installed

● Download from Vagrant Cloud, directly from vendors, or roll your own

● You can then share your own boxes with others

Page 17: Painless WordPress Dev Environments with Vagrant and Ansible

Rogue Repairman Productions | Alexandria, VA | [email protected] | 703-542-4025

Vagrant Cloud

Page 18: Painless WordPress Dev Environments with Vagrant and Ansible

Rogue Repairman Productions | Alexandria, VA | [email protected] | 703-542-4025

Step 2: The Vagrantfile

● A Ruby script that controls the configuration of the virtual machine

● Base box to start with● Networking setup● Available memory, CPU, disk● Synchronized folders● Which “provisioner” to use, and where to find its configuration files

Page 19: Painless WordPress Dev Environments with Vagrant and Ansible

Rogue Repairman Productions | Alexandria, VA | [email protected] | 703-542-4025

Inside the Vagrantfile

Page 20: Painless WordPress Dev Environments with Vagrant and Ansible

Rogue Repairman Productions | Alexandria, VA | [email protected] | 703-542-4025

Step 3: The Inventory File

● Tells Ansible which machines you want to run your provisioning scripts against

● In our case, it's just one machine, the local VM

● Specified in the Vagrantfile as ansible.inventory_path● Can also specify variables to pass to your Ansible “recipe” for

system setup

Page 21: Painless WordPress Dev Environments with Vagrant and Ansible

Rogue Repairman Productions | Alexandria, VA | [email protected] | 703-542-4025

Inside The Inventory File

Page 22: Painless WordPress Dev Environments with Vagrant and Ansible

Rogue Repairman Productions | Alexandria, VA | [email protected] | 703-542-4025

Step 4: The Playbook

● A text file in YAML format, telling Ansible step by step how to provision your system

● What's YAML? http://www.yaml.org/

● Each “play” in the playbook represents an action to be taken● Playbooks can be nested, so they can be developed as discrete

components ● Plays are (supposed to be) idempotent, so you can run them

multiple times without side effects

Page 23: Painless WordPress Dev Environments with Vagrant and Ansible

Rogue Repairman Productions | Alexandria, VA | [email protected] | 703-542-4025

Inside the Playbook

Page 24: Painless WordPress Dev Environments with Vagrant and Ansible

Putting It All Together: A Case Study

Page 25: Painless WordPress Dev Environments with Vagrant and Ansible

Rogue Repairman Productions | Alexandria, VA | [email protected] | 703-542-4025

VirtualBox + Vagrant + Ansible == WordPress

● To aid in my own work, I have created a set of scripts that let you rapidly deploy a fully functional WordPress environment on your local workstation

● It's on GitHub for your forking pleasure● https://github.com/jalefkowit/Vagrant-Ansible-Wordpress

● But you could do the same thing for Drupal, Symfony, Laravel, MediaWiki... whatever you want

● Learning these tools let you speed past futzing with system administration and get back to what you do best: writing beautiful PHP

Page 26: Painless WordPress Dev Environments with Vagrant and Ansible

Rogue Repairman Productions | Alexandria, VA | [email protected] | 703-542-4025

Thank You!

Jason A. LefkowitzPresident, Rogue Repairman Productions

http://roguerepairman.com

[email protected]

Technology sucks. We make it suck less.