Stef Horner: Vagrant
The Problem
Projects have different dependancies:
-
PHP, ruby, node, etc.
- apache config, ssh, etc.
- config
- OS versions
OSX, Ubuntu and CentOS all use different versions of apache
The Solution
Server Provisioning
Server Provisioning
Makes sure that a server meets certain requirements
Allows you to use an identical server for development
Basics
- You take a base OS, or "box"
- You install required software
- You setup some configuration
Word of the day: idempotence
An action that can be applied multiple times without changing the result beyond the initial application
-
Modulus - |x|
-
Loading a gun
Don't install things
Ensure that things are installed
vagrant up
-
Takes the specified box
-
Provisions it
-
Boots it up
vagrant ssh
SSHes into the vagrant box as the default user: vagrant
Handles authentication
Single command mode:
vagrant ssh -c "ls /"
ssh vagrant@127.0.0.1 "ls /"
Will run a command as the default user, then exit
Folder Sync
The project folder will be synced to the
/vagrant
folder on the box
It will be pseudo-chowned to
vagrant:vagrant
Have a Break
vagrant halt
Gracefully shuts down the box
vagrant destroy
Shuts down the box, and destroys the image
vagrant suspend
Stores the current state of the box
The Vagrantfile
The config file for vagrant
Uses ruby syntax
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu_10_04"
config.vm.box_url = "http://files.vagrantup.com/lucid32.box"
# more config goes here
end
Provisioning
-
Manual
-
Shell
-
Chef
-
Puppet
-
Ansible
-
Docker
-
Salt
Manual Provisioning
The most basic way of provisioning is to do it by hand
-
Slow
- Boring
- Error Prone
-
Not all of it gets done
- Has to be done every time
Shell Provisioning
Add the following to the Vagrantfile
config.vm.provision :shell, :inline => "echo woop woop woop"
config.vm.provision :shell, :path => "setup.sh"
This script gets run whenever the box gets provisioned
Puppet / Chef
-
Puppet: more expressive markup, made specifically for provisioning. Simpler.
- Chef: uses ruby, and can therefore use programming constructs
Chef sticks to the chef analogy for everything
Beyond that, the main difference is their communities
Vagrant
By Stef Horner
Vagrant
An intro to vagrant
- 517