Vagrant
Mitchell Hashimoto
@mitchellh
Vagrant
With a focus on Ops
Agenda
Agenda
What is Vagrant
Agenda
 What is Vagrant
Why use Vagrant
Agenda
           What is Vagrant
          Why use Vagrant
DevOps with Vagrant in mind
Vagrant
What is Vagrant?
The Grid
A tool for building and distributing
    virtualized environments.
A local cloud.
Create and tear down virtual machines
Create and tear down virtual machines

Use automation to provision and configure
Create and tear down virtual machines

Use automation to provision and configure

        Network multiple virtual machines
Create and tear down virtual machines

Use automation to provision and configure

        Network multiple virtual machines

       Package and distribute VM images
Vagrant
Why use Vagrant?
User space
                          Browser                       Editor
                                          Queue                       Other
             Music                        Server                      Server

   Web                DB                            App
                                    IRC                          IM
  Server             Server                        Server




                                Operating System
No isolation
No isolation

No repeatability
No isolation

No repeatability

 No verification
User space
                      Virtualized OS

   Browser   Editor
                            Web                       App
                                         DB Server
                           Server                    Server

     IRC      IM




                      Operating System
Isolation
Isolation

Mirror production
Isolation

                 Mirror production

Test Ops scripts with a free server
Isolation

                 Mirror production

Test Ops scripts with a free server

                Faster onboarding
Isolation

                 Mirror production

Test Ops scripts with a free server

                Faster onboarding

         Designers can do it, too!
Vagrant
DevOps
Goal: Develop
Cookbooks/Modules to run in a VM
       and production.
Little extra effort.
     Big gain.
Good practices.
Little extra effort.
     Big gain.
Good practices.
Don’t assume EC2/RackSpace/MyCloudInc

# Allow app servers to access DB
-A INPUT -p tcp
  -s <%= node[:ec2][:local_ipv4] %>
  --dport <%= node[:mysql][:port] %>
  -j ACCEPT
Don’t assume EC2/RackSpace/MyCloudInc

# Allow app servers to access DB
-A INPUT -p tcp
  -s <%= local_ip(node) %>
  --dport <%= node[:mysql][:port] %>
  -j ACCEPT
Don’t assume EC2/RackSpace/MyCloudInc

# Returns the local-network IP of a node
# based on the environment.
def local_ip(node)
  return “127.0.0.1” if in_vagrant?
  return node[:ec2][:local_ipv4] if in_ec2?
  raise “Unknown server environment.”
end
Short-circuit Recipes/Manifests


INFO: Chef Run complete in 1442.890442 seconds
INFO: Running report handlers
INFO: Report handlers complete
Short-circuit Recipes/Manifests

# Only install certain software when not
# in Vagrant.
if !in_vagrant?
  include_recipe “flume::node”
  include_recipe “kiip_monitoring::client”
  ...
end
Short-circuit Recipes/Manifests


INFO: Chef Run complete in 946.418511 seconds
INFO: Running report handlers
INFO: Report handlers complete




          Not great, but I’ll take 50% speedups.
Flexible Configuration
attributes = {
  :kiip_mongo => {
     :mount_ebs => false
  },
  :kiip_web => {
     :app_source => "folder"
  },
  ...
}
Role Composition
run_list => [
  “role[base]”,
  “role[kiip_mongodb]”,
  “role[kiip_memcached]”,
  “role[kiip_web]”,
  “role[kiip_utility]”
]


                 Normally different servers.
                  But no problem on one!
DevOps Zen
Vagrant
Is it battle tested?
vagrantup.com
github.com/mitchellh/vagrant

SF DevOps: Introducing Vagrant