Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Stabilize your environment, stabilize your code - Midwest PHP 2014

Stabilize your environment, stabilize your code - Midwest PHP 2014

Without a development environment that closely matches your production environment, the process of promoting your code from dev to prod will be fraught with peril. We will go into the fine details that you need to know to get started working with Vagrant, VirtualBox and Puppet, teaching the tools needed to not only stabilize your development environment, but improve the confidence you have in your code as it is promoted from development to production.

Find out more at: http://jmather.com/talks/midwest-php-2014/stabilize/

Jacob Mather

March 16, 2014
Tweet

More Decks by Jacob Mather

Other Decks in Programming

Transcript

  1. Stabilize your environment,
    stabilize your code
    Jacob Mather
    Software Engineer, Mashery

    View Slide

  2. Stabilize your environment, stabilize your code - MidwestPHP - March 16th, 2014
    Who am I?
    What I do:
    • Software Engineer at Mashery
    • Co-organizer of the

    San Francisco PHP User Group
    • Community Evangelist
    Where I can be found:
    • Blog: http://jmather.com
    • Twitter: @thejmather

    View Slide

  3. Stabilize your environment, stabilize your code - MidwestPHP - March 16th, 2014
    Why I am giving this talk

    View Slide

  4. Stabilize your environment, stabilize your code - MidwestPHP - March 16th, 2014
    Failure to specifically build an
    environment for development will
    directly impact developer
    productivity and product quality.

    View Slide

  5. Let’s talk about

    Vagrant

    View Slide

  6. Stabilize your environment, stabilize your code - MidwestPHP - March 16th, 2014
    What is Vagrant?
    A tool that allows you to create and configure lightweight,
    reproducible, and portable development environments.

    View Slide

  7. Stabilize your environment, stabilize your code - MidwestPHP - March 16th, 2014
    Why was Vagrant created?
    To solve the problem of how to have easy an to build development
    environment that is identical across the entire team.

    View Slide

  8. Stabilize your environment, stabilize your code - MidwestPHP - March 16th, 2014
    Vagrant terms
    • Box, or base box, is the ‘initial image’ of a virtual machine.
    • Host, or your computer, the machine running the VMs
    • Guest, or vm, referring to an individual VM instance
    • Provider, an adapter to a VMS (like VirtualBox or VMWare)
    • Provisioner, provides post-boot configuration of guests

    View Slide

  9. Stabilize your environment, stabilize your code - MidwestPHP - March 16th, 2014
    Basic Vagrant Commands
    • vagrant up - Turn guest on
    • vagrant halt - Turn guest off
    • vagrant status - Show guest status
    • vagrant destroy - Delete guest
    • vagrant suspend - Suspend guest
    • vagrant resume - Resume guest
    • vagrant ssh - SSH into guest

    View Slide

  10. Stabilize your environment, stabilize your code - MidwestPHP - March 16th, 2014
    How to use Vagrant
    • Install Vagrant - http://vagrantup.com
    • Check out your repository
    • Run: vagrant up

    View Slide

  11. Let’s talk about

    code

    View Slide

  12. Stabilize your environment, stabilize your code - MidwestPHP - March 16th, 2014
    Basic Vagrantfile
    Vagrant.configure("2")  do  |config|

       config.vm.box  =  "base-­‐box-­‐name"

       config.vm.box_url  =  "http://some/url.box"

    end


    View Slide

  13. Stabilize your environment, stabilize your code - MidwestPHP - March 16th, 2014
    Basic Vagrantfile (add file system)
    Vagrant.configure("2")  do  |config|

       config.vm.box  =  "base-­‐box-­‐name"

       config.vm.box_url  =  "http://some/url.box"

       config.vm.synced_folder  "/data",  "/vagrant_data"

    end


    View Slide

  14. Stabilize your environment, stabilize your code - MidwestPHP - March 16th, 2014
    Basic Vagrantfile (add port forwarding)
    Vagrant.configure("2")  do  |config|

       config.vm.box  =  "base-­‐box-­‐name"

       config.vm.box_url  =  "http://some/url.box"

       config.vm.synced_folder  "/data",  "/vagrant_data"

       config.vm.network  :forwarded_port,  guest:  80,  host:  8080

    end


    View Slide

  15. Let’s talk about

    clouds

    View Slide

  16. Stabilize your environment, stabilize your code - MidwestPHP - March 16th, 2014
    Replicating production matters
    If you are writing code that will be deployed to a multiple-host
    environment, why aren’t you writing your code in a multiple-
    host environment?

    View Slide

  17. Stabilize your environment, stabilize your code - MidwestPHP - March 16th, 2014
    Basic Vagrantfile
    Vagrant.configure("2")  do  |config|

       config.vm.hostname  =  "web-­‐server"

       config.vm.box  =  "base-­‐box-­‐name"

       config.vm.box_url  =  "http://some/url.box"

    end


    View Slide

  18. Stabilize your environment, stabilize your code - MidwestPHP - March 16th, 2014
    Basic Vagrantfile
    Vagrant.configure("2")  do  |config|  

       config.vm.hostname  =  "web-­‐server"

       config.vm.box  =  "base-­‐box-­‐name"

       config.vm.box_url  =  "http://some/url.box"

    end


    View Slide

  19. Stabilize your environment, stabilize your code - MidwestPHP - March 16th, 2014
    Basic Vagrantfile (Multi-Guest ready)
    Vagrant.configure("2")  do  |config|

       config.vm.define  "web-­‐server"  do  |node|

           node.vm.hostname  =  "web-­‐server"

           node.vm.box  =  "base-­‐box-­‐name"

           node.vm.box_url  =  "http://some/url.box"

       end

    end


    View Slide

  20. Stabilize your environment, stabilize your code - MidwestPHP - March 16th, 2014
    Basic Vagrantfile (Multi-Guest ready)
    Vagrant.configure("2")  do  |config|

       config.vm.define  "web-­‐server"  do  |node|

           node.vm.hostname  =  "web-­‐server"

           node.vm.box  =  "base-­‐box-­‐name"

           node.vm.box_url  =  "http://some/url.box"

       end

    end


    View Slide

  21. Stabilize your environment, stabilize your code - MidwestPHP - March 16th, 2014
    Basic Vagrantfile (Multi-Guest ready)
    Vagrant.configure("2")  do  |config|

       config.vm.define  "web-­‐server"  do  |node|

           node.vm.hostname  =  "web-­‐server"

           node.vm.box  =  "base-­‐box-­‐name"

           node.vm.box_url  =  "http://some/url.box"

       end

    end


    View Slide

  22. Stabilize your environment, stabilize your code - MidwestPHP - March 16th, 2014
    Basic Vagrantfile (Multi-Guest)
    Vagrant.configure("2")  do  |config|

       config.vm.define  "web-­‐server"  do  |node|

           node.vm.hostname  =  "web-­‐server"

           node.vm.box  =  "base-­‐box-­‐name"

           node.vm.box_url  =  "http://some/url.box"

       end

       config.vm.define  "db-­‐server"  do  |node|

           node.vm.hostname  =  "db-­‐server"

           node.vm.box  =  "base-­‐box-­‐name"  

           node.vm.box_url  =  "http://some/url.box"

       end

    end

    View Slide

  23. Stabilize your environment, stabilize your code - MidwestPHP - March 16th, 2014
    Basic Vagrantfile (Multi-Guest, useful, part 1)
    nodes  =  {

           'web-­‐server'  =>  {

                   :hostname  =>  'server.example.com',

                   :ipAddress  =>  '192.168.56.60',

           },

           'db-­‐server'  =>  {

                   :hostname  =>  'db.example.com',

                   :ipAddress  =>  '192.168.56.61',

           }

    }

    View Slide

  24. Stabilize your environment, stabilize your code - MidwestPHP - March 16th, 2014
    Basic Vagrantfile (Multi-Guest, useful, part 2)
    nodes  =  {  /*  ...  node  definition  ...  */  };

    Vagrant.configure("2")  do  |config|

       nodes.each_pair  do  |name,  options|

           machineName  =  options[:hostname]

           ipAddy  =  options[:ipAddress]  
           config.vm.define  name  do  |node|

               node.vm.box  =  "base-­‐box-­‐name"

               node.vm.box_url  =  "http://some/url.box"

               node.vm.hostname  =  machineName

               node.vm.network  :private_network,  ip:  ipAddy

           end

       end

    end

    View Slide

  25. Stabilize your environment, stabilize your code - MidwestPHP - March 16th, 2014
    Basic Vagrantfile (Multi-Guest, useful, part 2)
    nodes  =  {  /*  ...  node  definition  ...  */  };

    Vagrant.configure("2")  do  |config|

       nodes.each_pair  do  |name,  options|

           machineName  =  options[:hostname]

           ipAddy  =  options[:ipAddress]  
           config.vm.define  name  do  |node|

               node.vm.box  =  "base-­‐box-­‐name"

               node.vm.box_url  =  "http://some/url.box"

               node.vm.hostname  =  machineName

               node.vm.network  :private_network,  ip:  ipAddy

           end

       end

    end

    View Slide

  26. Stabilize your environment, stabilize your code - MidwestPHP - March 16th, 2014
    Basic Vagrantfile (Multi-Guest, useful, part 2)
    nodes  =  {  /*  ...  node  definition  ...  */  };

    Vagrant.configure("2")  do  |config|

       nodes.each_pair  do  |name,  options|

           machineName  =  options[:hostname]

           ipAddy  =  options[:ipAddress]  
           config.vm.define  name  do  |node|

               node.vm.box  =  "base-­‐box-­‐name"

               node.vm.box_url  =  "http://some/url.box"

               node.vm.hostname  =  machineName

               node.vm.network  :private_network,  ip:  ipAddy

           end

       end

    end

    View Slide

  27. Stabilize your environment, stabilize your code - MidwestPHP - March 16th, 2014
    Basic Vagrantfile (Multi-Guest, useful, part 2)
    nodes  =  {  /*  ...  node  definition  ...  */  };

    Vagrant.configure("2")  do  |config|

       nodes.each_pair  do  |name,  options|

           machineName  =  options[:hostname]

           ipAddy  =  options[:ipAddress]  
           config.vm.define  name  do  |node|

               node.vm.box  =  "base-­‐box-­‐name"

               node.vm.box_url  =  "http://some/url.box"

               node.vm.hostname  =  machineName

               node.vm.network  :private_network,  ip:  ipAddy

           end

       end

    end

    View Slide

  28. Stabilize your environment, stabilize your code - MidwestPHP - March 16th, 2014
    Basic Vagrantfile (Multi-Guest, useful, part 2)
    nodes  =  {  /*  ...  node  definition  ...  */  };

    Vagrant.configure("2")  do  |config|

       nodes.each_pair  do  |name,  options|

           machineName  =  options[:hostname]

           ipAddy  =  options[:ipAddress]  
           config.vm.define  name  do  |node|

               node.vm.box  =  "base-­‐box-­‐name"

               node.vm.box_url  =  "http://some/url.box"

               node.vm.hostname  =  machineName

               node.vm.network  :private_network,  ip:  ipAddy

           end

       end

    end

    View Slide

  29. Stabilize your environment, stabilize your code - MidwestPHP - March 16th, 2014
    Basic Vagrantfile (Multi-Guest, useful, part 2)
    nodes  =  {  /*  ...  node  definition  ...  */  };

    Vagrant.configure("2")  do  |config|

       nodes.each_pair  do  |name,  options|

           machineName  =  options[:hostname]

           ipAddy  =  options[:ipAddress]  
           config.vm.define  name  do  |node|

               node.vm.box  =  "base-­‐box-­‐name"

               node.vm.box_url  =  "http://some/url.box"

               node.vm.hostname  =  machineName

               node.vm.network  :private_network,  ip:  ipAddy

           end

       end

    end

    View Slide

  30. Let’s talk about

    Providers

    View Slide

  31. Stabilize your environment, stabilize your code - MidwestPHP - March 16th, 2014
    Vagrant Providers
    !
    Providers
    !
    Vagrant

    View Slide

  32. Stabilize your environment, stabilize your code - MidwestPHP - March 16th, 2014
    Vagrant Providers
    VirtualBox
    VMWare (WS or Fusion)
    Parallels Desktop
    !
    Providers
    !
    Vagrant

    View Slide

  33. Stabilize your environment, stabilize your code - MidwestPHP - March 16th, 2014
    Vagrant Providers
    VirtualBox
    VMWare (WS or Fusion)
    Parallels Desktop
    Amazon AWS
    Digital Ocean
    !
    Providers
    !
    Vagrant

    View Slide

  34. Stabilize your environment, stabilize your code - MidwestPHP - March 16th, 2014
    Vagrant Providers (desktop)
    • VirtualBox is FREE! (sort of)
    • Built in FS bridging is historically bad but getting better
    • Newer versions are less stable (use 4.2.16!!)
    • VMWare (Workstation or Fusion!) is PAID!
    • You have to buy both VMWare and provider
    • Supposed to be more stable and snappy
    • Parallels Desktop adapter is FREE!
    • Open source project
    • You do still have to buy Parallels Desktop

    View Slide

  35. Stabilize your environment, stabilize your code - MidwestPHP - March 16th, 2014
    Vagrant Providers (cloud)
    • Amazon AWS
    • Digital Ocean
    • RackSpace Cloud

    View Slide

  36. Stabilize your environment, stabilize your code - MidwestPHP - March 16th, 2014
    Vagrant Provider Limits
    Spinning up guests is cool, but what do I do with a box once
    it’s up? How do I control it? How do I make it useful?
    !
    Computing hardware without software is nearly useless.

    View Slide

  37. Let’s talk about

    Provisioners

    View Slide

  38. Stabilize your environment, stabilize your code - MidwestPHP - March 16th, 2014
    Vagrant Provisioners
    !
    Provisioners
    !
    Vagrant

    View Slide

  39. Stabilize your environment, stabilize your code - MidwestPHP - March 16th, 2014
    Shell Scripts
    Puppet
    Chef
    Ansible
    Vagrant Provisioners
    !
    Provisioners
    !
    Vagrant

    View Slide

  40. Let’s talk about

    Puppet

    View Slide

  41. Stabilize your environment, stabilize your code - MidwestPHP - March 16th, 2014
    What is Puppet?
    Puppet, an automated administrative engine for your Linux, Unix,
    and Windows systems, performs administrative tasks (such as
    adding users, installing packages, and updating server
    configurations) based on a centralized specification.

    View Slide

  42. Stabilize your environment, stabilize your code - MidwestPHP - March 16th, 2014
    Why was Puppet created?
    Puppet was created to provide a declarative way to define system
    and software configuration.

    View Slide

  43. Stabilize your environment, stabilize your code - MidwestPHP - March 16th, 2014
    Puppet terms
    • Manifests - This is “application” code
    • Modules - This is “library” code
    • Templates - Exactly as it sounds
    • Facter - Environment data
    • Hiera - Configuration data

    View Slide

  44. Stabilize your environment, stabilize your code - MidwestPHP - March 16th, 2014
    How to use Puppet?
    Select a base box for Vagrant from Puppet Labs
    !
    http://puppet-vagrant-boxes.puppetlabs.com/
    !
    I use CentOS 6.4 for VirtualBox

    View Slide

  45. Let’s talk about

    code

    View Slide

  46. Stabilize your environment, stabilize your code - MidwestPHP - March 16th, 2014
    Basic Vagrantfile
    Vagrant.configure("2")  do  |config|

       config.vm.box  =  "base-­‐box-­‐name"

       config.vm.box_url  =  "http://some/url.box"

    end


    View Slide

  47. Stabilize your environment, stabilize your code - MidwestPHP - March 16th, 2014
    Basic Vagrantfile
    Vagrant.configure("2")  do  |config|

       config.vm.box  =  "base-­‐box-­‐name"

       config.vm.box_url  =  “http://some/url.box"  
    !
    !
    !
    !

    end


    View Slide

  48. Stabilize your environment, stabilize your code - MidwestPHP - March 16th, 2014
    Basic Vagrantfile
    Vagrant.configure("2")  do  |config|

       config.vm.box  =  "base-­‐box-­‐name"

       config.vm.box_url  =  “http://some/url.box"  
    !
    !
    !
    !

    end

    View Slide

  49. Stabilize your environment, stabilize your code - MidwestPHP - March 16th, 2014
    Basic Vagrantfile (add Puppet)
    Vagrant.configure("2")  do  |config|

       config.vm.box  =  "base-­‐box-­‐name"

       config.vm.box_url  =  "http://some/url.box"

       config.vm.provision  :puppet  do  |puppet|

           puppet.manifests_path  =  "manifests/"

           puppet.manifest_file    =  “init.pp"

           puppet.module_path  =  "modules/"

       end

    end


    View Slide

  50. Stabilize your environment, stabilize your code - MidwestPHP - March 16th, 2014
    Basic Vagrantfile (add Puppet)
    Vagrant.configure("2")  do  |config|

       config.vm.box  =  "base-­‐box-­‐name"

       config.vm.box_url  =  "http://some/url.box"

       config.vm.provision  :puppet  do  |puppet|

           puppet.manifests_path  =  "manifests/"

           puppet.manifest_file    =  “init.pp"

           puppet.module_path  =  "modules/"

       end

    end


    View Slide

  51. Stabilize your environment, stabilize your code - MidwestPHP - March 16th, 2014
    Basic Puppet Manifest (init.pp)
    notify  {  "Look!  My  puppet  code  is  working!":  }


    View Slide

  52. Stabilize your environment, stabilize your code - MidwestPHP - March 16th, 2014
    Basic Puppet Manifest (init.pp, add Apache)
    notify  {  "Look!  My  puppet  code  is  working!":  }

       

    package  {  "httpd":

       ensure  =>  present,

    }

       

    service  {  "httpd":

       require  =>  Package["httpd"],

       ensure  =>  running,

       enabled  =>  true,

    }

    View Slide

  53. Stabilize your environment, stabilize your code - MidwestPHP - March 16th, 2014
    Basic Puppet Manifest (refactored Apache)
    #  manifests/init.pp

    notify  {  "Code  works!":  }

    require  server::httpd

    #  modules/server/manifests/httpd.pp

    class  server::httpd  {

       package  {  "httpd":

           ensure  =>  present,

       }

       service  {  "httpd":

           require  =>  Package["httpd"],

           ensure  =>  running,

           enabled  =>  true,

       }

    }

    View Slide

  54. Stabilize your environment, stabilize your code - MidwestPHP - March 16th, 2014
    Puppet Manifest (controlling flow)
    #  manifests/init.pp  
    notify  {  "Say  me  third":

       require  =>  Notify["Say  me  second"],

    }

       

    notify  {  "Say  me  second":

       require  =>  Notify["Say  me  first"],

    }

       

    notify  {  "Say  me  first":  }

    View Slide

  55. Stabilize your environment, stabilize your code - MidwestPHP - March 16th, 2014
    Puppet Manifest (controlling flow)
    #  manifests/init.pp  
    notify  {  "Say  me  third":

       require  =>  Notify["Say  me  second"],

    }

       

    notify  {  "Say  me  second":

       require  =>  Notify["Say  me  first"],

    }

       

    notify  {  "Say  me  first":  }
    Output
    Say me first
    Say me second
    Say me third

    View Slide

  56. Stabilize your environment, stabilize your code - MidwestPHP - March 16th, 2014
    Puppet Manifest (adding parameters)
    #  modules/server/manifests/writefile.pp

    class  server::writefile  ($content)  {

       file  {  "/tmp/test":

           content  =>  $content,

       }

    }


    #  or,  to  provide  a  default…  
    class  server::writefile  ($content  =  "")  {

       file  {  "/tmp/test":

           content  =>  $content

       }

    }

    View Slide

  57. Stabilize your environment, stabilize your code - MidwestPHP - March 16th, 2014
    Puppet Manifest (passing parameters)
    #  manifests/init.pp  -­‐-­‐  using  defaults

    include  server::writetestfile


    #  manifests/init.pp  -­‐-­‐  passing  custom  value

    class  {  "server::writetestfile":

       content  =>  "test  content",

    }

    View Slide

  58. Stabilize your environment, stabilize your code - MidwestPHP - March 16th, 2014
    Puppet Manifest (including classes)
    #  manifests/init.pp  
    #  the  class  below  must  be  loaded  BEFORE  guest

    require  server::writetestfile

       

    #  the  class  below  must  be  loaded  WITH  guest

    include  server::writetestfile  
       

    #  the  class  below  must  be  loaded  AFTER  guest

    class  {  "server::writetestfile":

       content  =>  "test  content",

    }

    View Slide

  59. Let’s talk about

    how to do things conditionally

    View Slide

  60. Stabilize your environment, stabilize your code - MidwestPHP - March 16th, 2014
    External Input in Puppet
    There are three primary sources of where data that branches your
    logic will come from:
    !
    • User Space Variables
    • $things = “you set yourself”
    • Facts
    • Specific details about your current environment, such as the
    name of the host, ip address, operating system, etc...
    • Hiera
    • Configuration you pass in to enable building for multiple
    configurations from the same shared codebase
    !

    View Slide

  61. Stabilize your environment, stabilize your code - MidwestPHP - March 16th, 2014
    Puppet Manifest (variables)
    #  local  variable

    $host  =  "mybox"


    if  ($host  ==  "mybox")  {

       notify  {  "Box!":  }

    }


    if  ($host  ==  "mybox")  {

       notify  {  "${host}!":  }

    }

    View Slide

  62. Stabilize your environment, stabilize your code - MidwestPHP - March 16th, 2014
    Puppet Manifest (scope)
    #  fact  -­‐  environment  configuration

    if  ($hostname  ==  "box")  {  notify  {  "Box!":  }  }  
                                                                         #  outputs:  Box!


    View Slide

  63. Stabilize your environment, stabilize your code - MidwestPHP - March 16th, 2014
    Puppet Manifest (variables, facts, scope)
    #  fact  -­‐  environment  configuration

    if  ($hostname  ==  "box")  {  notify  {  "Box!":  }  }  
                                                                         #  outputs:  Box!

    if  ($::hostname  ==  "box")  {  notify  {  "Box!":  }  }  
                                                                         #  outputs:  Box!


    View Slide

  64. Stabilize your environment, stabilize your code - MidwestPHP - March 16th, 2014
    Puppet Manifest (variables, facts, scope)
    #  fact  -­‐  environment  configuration

    if  ($hostname  ==  "box")  {  notify  {  "Box!":  }  }  
                                                                         #  outputs:  Box!

    if  ($::hostname  ==  "box")  {  notify  {  "Box!":  }  }  
                                                                         #  outputs:  Box!

    #  assign  $hostname  locally...

    $hostname  =  "some  string"


    View Slide

  65. Stabilize your environment, stabilize your code - MidwestPHP - March 16th, 2014
    Puppet Manifest (variables, facts, scope)
    #  fact  -­‐  environment  configuration

    if  ($hostname  ==  "box")  {  notify  {  "Box!":  }  }  
                                                                         #  outputs:  Box!

    if  ($::hostname  ==  "box")  {  notify  {  "Box!":  }  }  
                                                                         #  outputs:  Box!

    #  assign  $hostname  locally...

    $hostname  =  "some  string"

    if  ($hostname  ==  "box")  {  notify  {  "Box!":  }  }  
                                                                         #  no  output


    View Slide

  66. Stabilize your environment, stabilize your code - MidwestPHP - March 16th, 2014
    Puppet Manifest (variables, facts, scope)
    #  fact  -­‐  environment  configuration

    if  ($hostname  ==  "box")  {  notify  {  "Box!":  }  }  
                                                                         #  outputs:  Box!

    if  ($::hostname  ==  "box")  {  notify  {  "Box!":  }  }  
                                                                         #  outputs:  Box!

    #  assign  $hostname  locally...

    $hostname  =  "some  string"

    if  ($hostname  ==  "box")  {  notify  {  "Box!":  }  }  
                                                                         #  no  output

    if  ($::hostname  ==  "box")  {  notify  {  "Box!":  }  }  
                                                                         #  outputs:  Box!


    View Slide

  67. Stabilize your environment, stabilize your code - MidwestPHP - March 16th, 2014
    Puppet Manifest (facts, debugging)
    #  what  facts  are  there?  Let’s  find  out!

       

    #  this  should  be  one  line,  but  it  is  too  long  to  fit

    $tmpl  =  "                  (String)  &&  v.is_a?(String)  )  }.to_yaml  %>"

       

    #  create  a  file...

    file  {  "/tmp/facts.yaml":

       content  =>  inline_template($tmlp),

    }

    View Slide

  68. Stabilize your environment, stabilize your code - MidwestPHP - March 16th, 2014
    Puppet Manifest (facts, debugging, cont…)
    What values are available?
    !
    architecture, kernelversion, netmask_eth1, rubyversion,
    operatingsystem, memorysize_mb, processor0, interfaces,
    uptime, physicalprocessorcount, osfamily, selinux,
    operatingsystemrelease, ipaddress, and much more…

    View Slide

  69. Stabilize your environment, stabilize your code - MidwestPHP - March 16th, 2014
    Puppet Manifest (hiera)
    #  hieradata/common.yml

    thing:  "Something  Special"

    #  modules/server/manifests/writefile.pp

    class  server::writefile  ()  {

       $content  =  hiera('thing')

       file  {  "/tmp/test":

           content  =>  $content

       }

    }

    View Slide

  70. Stabilize your environment, stabilize your code - MidwestPHP - March 16th, 2014
    Puppet Manifest (hiera, really neat)
    #  hieradata/common.yml

    server::writefile::content:  "Something  Special"

    #  modules/server/manifests/writefile.pp

    class  server::writefile  ($content  =  "")  {

       file  {  "/tmp/test":

           content  =>  $content

       }

    }

    View Slide

  71. Stabilize your environment, stabilize your code - MidwestPHP - March 16th, 2014
    Puppet Manifest (if conditionals)
    if  ("a"  ==  "b")  {

       notify  {  "Inconceivable!":  }

    }  elsif  ("hello"  =~  "help")  {

       notify  {  "Regex!":  }

    }  else  {

       notify  {  "Echo  something...":  }

    }

    View Slide

  72. Stabilize your environment, stabilize your code - MidwestPHP - March 16th, 2014
    Puppet Manifest (case conditionals)
    #  $::operatingsystem  is  a  fact,  provided  by  Facter

    case  $::operatingsystem  {

       centos,  redhat:  {  $apache  =  "httpd"  }

       debian,  ubuntu:  {  $apache  =  "apache2"  }

       default:  {  fail("Unrecognized  operating  system")  }

    }


    case  $::operatingsystem  {

       /linux/:  {  fail("We  don’t  support  Linux!”)  }

    }

    View Slide

  73. Stabilize your environment, stabilize your code - MidwestPHP - March 16th, 2014
    Puppet Manifest (selector conditionals)
    #  $::operatingsystem  is  a  fact,  provided  by  Facter

    $package  =  $::operatingsystem  ?  {

       centos  =>  "httpd",

       redhat  =>  "httpd",

       /(i?)(ubuntu|debian)/  =>  "apache2",

       default  =>  undef

    }

    View Slide

  74. Let’s talk about

    real multiple guest configuration

    View Slide

  75. Stabilize your environment, stabilize your code - MidwestPHP - March 16th, 2014
    Define our guest nodes (Vagrantfile)
    nodes  =  {

           'web'  =>  {

                   :hostname  =>  'web-­‐server.example.com',

                   :ipAddress  =>  '192.168.56.60',

           },

           'db'  =>  {

                   :hostname  =>  'db-­‐server.example.com',

                   :ipAddress  =>  '192.168.56.61',

           }

    }

    View Slide

  76. Stabilize your environment, stabilize your code - MidwestPHP - March 16th, 2014
    Define our guest nodes (Vagrantfile)
    nodes  =  {  /*  ...  node  definition  ...  */  };


    View Slide

  77. Stabilize your environment, stabilize your code - MidwestPHP - March 16th, 2014
    Tell Vagrant about them (Vagrantfile)
    nodes  =  {  /*  ...  node  definition  ...  */  };

    Vagrant.configure("2")  do  |config|

       nodes.each_pair  do  |name,  options|

           hostname  =  options[:hostname]

           ipAddy  =  options[:ipAddress]

           config.vm.define  name  do  |node|

               node.vm.box  =  "base-­‐box-­‐name"

               node.vm.box_url  =  "http://some/url.box"

               node.vm.hostname  =  hostname

               node.vm.network  :private_network,  ip:  ipAddy

           end

       end

    end

    View Slide

  78. Stabilize your environment, stabilize your code - MidwestPHP - March 16th, 2014
    Tell Vagrant about them (Vagrantfile)
    nodes  =  {  /*  ...  node  definition  ...  */  };

    Vagrant.configure("2")  do  |config|

       nodes.each_pair  do  |name,  options|

           config.vm.define  name  do  |node|

               /*  ...  basic  node  configuration  ...  */  
    !
    !
    !
    !
    !
           end

       end

    end

    View Slide

  79. Stabilize your environment, stabilize your code - MidwestPHP - March 16th, 2014
    Tell Vagrant about them (Vagrantfile)
    nodes  =  {  /*  ...  node  definition  ...  */  };

    Vagrant.configure("2")  do  |config|

       nodes.each_pair  do  |name,  options|

           config.vm.define  name  do  |node|

               /*  ...  basic  node  configuration  ...  */  
    !
    !
    !
    !
    !
           end

       end

    end

    View Slide

  80. Stabilize your environment, stabilize your code - MidwestPHP - March 16th, 2014
    nodes  =  {  /*  ...  node  definition  ...  */  }

    Vagrant.configure("2")  do  |config|

       nodes.each_pair  do  |name,options|

           config.vm.define  name  do  |node|

               /*  ...  basic  node  configuration  ...  */  
               node.vm.provision  :puppet  do  |puppet|

                   puppet.manifests_path  =  "manifests/"

                   puppet.manifest_file    =  "init.pp"

                   puppet.module_path  =  "modules/"

               end  
           end

       end

    end
    Tell Vagrant about Puppet (Vagrantfile)

    View Slide

  81. Stabilize your environment, stabilize your code - MidwestPHP - March 16th, 2014
    Tell Puppet about the guest nodes
    #  file:  manifests/init.pp

    if  ($::hostname  ==  "web-­‐1.example.com")  {

       #  only  run  for  web  server

    }


    if  ($::hostname  ==  "db-­‐1.example.com")  {

       #  only  run  for  db  server

    }

    View Slide

  82. Stabilize your environment, stabilize your code - MidwestPHP - March 16th, 2014
    Tell Puppet about the guest nodes (redux)
    #  file:  manifests/init.pp

    if  ($::hostname  =~  /^web-­‐/)  {

       #  only  run  for  web  servers

    }


    if  ($::hostname  =~  /^db-­‐/)  {

       #  only  run  for  db  servers

    }

    View Slide

  83. Let’s talk about

    how everything ties together

    View Slide

  84. Stabilize your environment, stabilize your code - MidwestPHP - March 16th, 2014
    Shell Scripts
    Puppet
    Chef
    Ansible
    VirtualBox
    VMWare (WS or Fusion)
    Parallels Desktop
    Amazon AWS
    Digital Ocean
    Vagrant Architecture
    !
    Providers
    !
    Provisioners
    !
    Vagrant

    View Slide

  85. Let’s talk about

    how to convince your boss

    View Slide

  86. Stabilize your environment, stabilize your code - MidwestPHP - March 16th, 2014
    Where do you develop your code?

    View Slide

  87. Stabilize your environment, stabilize your code - MidwestPHP - March 16th, 2014
    Production?

    View Slide

  88. Stabilize your environment, stabilize your code - MidwestPHP - March 16th, 2014
    Not Production?

    View Slide

  89. Stabilize your environment, stabilize your code - MidwestPHP - March 16th, 2014
    “My Computer?”

    View Slide

  90. Stabilize your environment, stabilize your code - MidwestPHP - March 16th, 2014
    “Development”

    View Slide

  91. Stabilize your environment, stabilize your code - MidwestPHP - March 16th, 2014
    A Development Environment

    View Slide

  92. Stabilize your environment, stabilize your code - MidwestPHP - March 16th, 2014
    Why developing in production is really bad
    Assuming, of course, that you are testing your code before you
    make it live.
    Production should always move from one stable version of code to
    another stable version of code. When you edit code in production,
    you inherently introduce instability, and can no longer be assured
    that your code is running as tested.

    View Slide

  93. Stabilize your environment, stabilize your code - MidwestPHP - March 16th, 2014
    Why developing on a non production setup
    is also bad
    Debugging environmental issues is slow and painful.
    Developers should be solving problems that are in your
    software, not debugging configuration issues in your
    environment.
    When you build your code in an environment that isn’t related to
    production in any tangible way, you will often have constant
    reminders just how different your development environment is from
    production.

    View Slide

  94. Stabilize your environment, stabilize your code - MidwestPHP - March 16th, 2014
    Where your development environment lives
    Remote
    • Easy for operations to set up
    • Easy to enforce a rigid structure
    • Limits developer’s choice of tool
    chain selection
    • Can get expensive and
    complicated to maintain
    • Developers must be online to do
    any development
    Local
    • Can require beefier hardware
    • Can take extra work to set up
    • Developers have the freedom to
    work how they work best
    • Developers can assist with
    infrastructural initiatives

    View Slide

  95. Stabilize your environment, stabilize your code - MidwestPHP - March 16th, 2014
    Bad development environments will sap the resources out of
    your team. In addition to the time spent developing and testing
    new code and fixing bugs, you will spend time:
    When development environments attack
    Debugging broken environments or settings
    Debugging broken behavior between dev and prod
    Debugging broken behavior between two dev systems
    Working in broken ways because “it works”

    View Slide

  96. Stabilize your environment, stabilize your code - MidwestPHP - March 16th, 2014
    If your development environments do
    not properly mirror production, you
    won’t know if your code really works
    until you make it live.

    View Slide

  97. Let’s talk about

    what you should remember

    View Slide

  98. Stabilize your environment, stabilize your code - MidwestPHP - March 16th, 2014
    Takeaways
    • Bad (or unstable) environments (be it dev, qa, staging, or
    prod) hurt developers.

    View Slide

  99. Stabilize your environment, stabilize your code - MidwestPHP - March 16th, 2014
    Takeaways
    • Bad (or unstable) environments (be it dev, qa, staging, or
    prod) hurt developers.
    • Puppet lets you automate all of the configuration of your
    systems (dev, qa, staging, and prod), ensuring
    consistency between them.

    View Slide

  100. Stabilize your environment, stabilize your code - MidwestPHP - March 16th, 2014
    Takeaways
    • Bad (or unstable) environments (be it dev, qa, staging, or
    prod) hurt developers.
    • Puppet lets you automate all of the configuration of your
    systems (dev, qa, staging, and prod), ensuring
    consistency between them.
    • Vagrant is easy to use, and will let you use your
    production puppet configs to build development
    environments.

    View Slide

  101. Stabilize your environment, stabilize your code - MidwestPHP - March 16th, 2014
    Takeaways
    • Bad (or unstable) environments (be it dev, qa, staging, or
    prod) hurt developers.
    • Puppet lets you automate all of the configuration of your
    systems (dev, qa, staging, and prod), ensuring
    consistency between them.
    • Vagrant is easy to use, and will let you use your
    production puppet configs to build development
    environments.
    • You will manage server configuration, whether you
    decide to or not. If you choose not to do it formally it will
    come back to bite you when you forget something later.

    View Slide

  102. Let’s talk about

    where to go from here

    View Slide

  103. Stabilize your environment, stabilize your code - MidwestPHP - March 16th, 2014
    If you’re still not sold...
    h"p://PuPHPet.com/
    /
    PuPHPet/provides/a/
    simple/config/tool/for/
    those/who/don’t/want/
    to/=nker/with/puppet/
    and/need/a/LAMP/stack/
    up/and/running/NOW./

    View Slide

  104. Stabilize your environment, stabilize your code - MidwestPHP - March 16th, 2014
    And also look at...
    • Packer
    • http://packer.io
    • Take your Vagrant and Puppet usage to the next level by
    using Packer to pre-provision images for easy first spins
    • Build prebuilt systems for multiple VMS and cloud
    platforms
    • Docker
    • http://docker.io
    • A different idea of how to build multiple machine VM
    environments

    View Slide

  105. Stabilize your environment, stabilize your code - MidwestPHP - March 16th, 2014
    And don’t forget...
    • Vagrant and Puppet Git Repository
    • https://github.com/jmather/vagrant-and-puppet

    View Slide

  106. Stabilize your environment, stabilize your code - MidwestPHP - March 16th, 2014
    Thank you!
    More information about this talk can be found at:
    !
    http://bit.ly/midwestphp-stabilize
    !
    RATE MY TALK AT:
    https://joind.in/10567
    !
    PLEASE LEAVE FEEDBACK
    It’s the only way I can improve

    View Slide