Date post: | 19-Jun-2015 |
Category: |
Technology |
Upload: | jason-lefkowitz |
View: | 378 times |
Download: | 1 times |
Painless WordPress Development Environments with Vagrant and Ansible
October 7, 2014
You need a server
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?
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?
“There's got to be a better way!”
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
Rogue Repairman Productions | Alexandria, VA | [email protected] | 703-542-4025
Three Tools
● VirtualBox: virtualization software● Vagrant: encapsulates virtual environments● Ansible: easy configuration management
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
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
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
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
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
Let's get to work
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
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
Rogue Repairman Productions | Alexandria, VA | [email protected] | 703-542-4025
Inside the Vagrantfile
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
Rogue Repairman Productions | Alexandria, VA | [email protected] | 703-542-4025
Inside The Inventory File
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
Putting It All Together: A Case Study
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
Rogue Repairman Productions | Alexandria, VA | [email protected] | 703-542-4025
Thank You!
Jason A. LefkowitzPresident, Rogue Repairman Productions
http://roguerepairman.com
Technology sucks. We make it suck less.