Virtualized DevelopmentEnvironments with Vagrant           Ian Chilton      PHP North East - 14th May 2012
IntroductionIan ChiltonBetter Brand Agencyhttp://www.betterbrandagency.comhttp://www.bettercommunities.co.ukTwitter: @ichi...
Contents- Introduction to:    - Development Environments    - Virtualization- Why Virtualize your development environment?...
Development Environments
Development EnvironmentsWe don’t want to be working on live sites.
Development EnvironmentsWe don’t want to be working on live sites.So we setup a development environment.
Development EnvironmentsWe don’t want to be working on live sites.So we setup a development environment.DEV          Stagi...
Development EnvironmentsWe don’t want to be working on live sites.So we setup a development environment.                  ...
Development Environments       We don’t want to be working on live sites.       So we setup a development environment.    ...
Development Environments       We don’t want to be working on live sites.       So we setup a development environment.    ...
Development Environments
Development EnvironmentsNumber of (valid) ways:
Development EnvironmentsNumber of (valid) ways: - Copy of site (on live server)    - Can easily affect the live site.
Development EnvironmentsNumber of (valid) ways: - Copy of site (on live server)    - Can easily affect the live site. - Sh...
Development Environments
Development EnvironmentsNumber of (valid) ways: - continued
Development EnvironmentsNumber of (valid) ways: - continued - Develop Locally:    - MAMP (mac) or WAMP (windows)    - Home...
Development EnvironmentsNumber of (valid) ways: - continued - Develop Locally:    - MAMP (mac) or WAMP (windows)    - Home...
Development Environments
Development EnvironmentsConsider these scenarios (just some examples of many...)
Development EnvironmentsConsider these scenarios (just some examples of many...)The methods on the previous slides could i...
Development Environments
Development EnvironmentsConsider these scenarios (just some examples of many...)
Development EnvironmentsConsider these scenarios (just some examples of many...)Both Windows and OS X use case insensitive...
Virtualization
VirtualizationSuch bugs can be very difficult and time consuming to track down.
VirtualizationSuch bugs can be very difficult and time consuming to track down.The lesson...We really need to develop on th...
Virtualization
VirtualizationVirtualization is a technology where by a number of “virtualmachines” can be hosted on top of a single machi...
VirtualizationVirtualization is a technology where by a number of “virtualmachines” can be hosted on top of a single machi...
VirtualizationVirtualization is a technology where by a number of “virtualmachines” can be hosted on top of a single machi...
VirtualizationVirtualization is a technology where by a number of “virtualmachines” can be hosted on top of a single machi...
Types of VirtualizationFull VirtualizationAlmost complete simulation of the actual hardware.This allows the guest operatin...
Types of VirtualizationParavirtualizationThe hardware environment is not simulated.The guest operating system is specially...
Types of VirtualizationHardware Assisted VirtualizationModern Intel or AMD CPU’s contain native virtualization functionali...
Types of VirtualizationOperating System Level Virtualization (aka. containers)The virtualization is implemented in softwar...
Advantages of Using Virtualization
Advantages of Using Virtualization- We can run the exact same operating system and setup as theproduction boxes, on top of...
Disadvantages of Using Virtualization
Disadvantages of Using Virtualization- Many of the products we’ve mentioned require Linux (or anotherUNIX operating system...
Disadvantages of Using Virtualization- Many of the products we’ve mentioned require Linux (or anotherUNIX operating system...
VagrantCreated by Mitchell Hashimoto and John BenderCommand line interface/wrapper around Oracle’s free VirtualBoxsoftware...
VagrantWe can use vagrant machines for:- Development- Testing- Experimenting new/different software/settings- Testing confi...
Apprehensions
Apprehensions- Won’t it be slow? - Headless Linux VM’s aren’t as resource hungry as a Windowsvirtualized.- I want to use m...
Install Vagrant
Install Vagrant- Install Oracle Virtualbox (free from: http://virtualbox.org) - versionsfor Windows, Mac OS X or Linux. • ...
Base Boxes
Base BoxesPre-packaged operating system images.Official base boxes - Ubuntu LTS (long term support) releases.Ubuntu 10.04 (...
Basic Vagrant Usage
Basic Vagrant Usage$ mkdir vagrant$ cd vagrant$ mkdir mydev$ cd mydevCreate a new config file (VagrantFile) for this instanc...
Basic Vagrant Usage
Basic Vagrant UsageVagrant automatically maps /vagrant inside the VM to the directoryon the host:vagrant@vagrant:~$ ls /va...
Vagrant Configuration
Vagrant ConfigurationThe “vagrant init” created a VagrantFile for this VM.Vagrant::Config.run do |config|    config.vm.box ...
Vagrant Configuration
Vagrant ConfigurationGUI or Headless?:Vagrant::Config.run do |config|    config.vm.box = "lucid32"      # Boot with a GUI s...
Vagrant Configuration
Vagrant ConfigurationPort Forwarding:Vagrant::Config.run do |config|    config.vm.box = "lucid32"      # Map port 8080 on t...
Vagrant Configuration
Vagrant ConfigurationControl VirtualBox:Vagrant::Config.run do |config|    config.vm.box = "lucid32"      # Make the VM hav...
Vagrant Configuration
Vagrant ConfigurationMultiple Machines:Vagrant::Config.run do |config|  # Web Server:  config.vm.define :web do |web_config...
Vagrant Configuration
Vagrant ConfigurationNetworking:- Host Only - local communication between different VM’s.  Vagrant::Config.run do |config| ...
Vagrant Configuration
Vagrant ConfigurationPackaging:Use as a starting point, or distribute instances.$ vagrant package --vagrantfile Vagrantfile...
Vagrant Plugins
Vagrant PluginsVagrant Box.es - Gareth Rushgrove has created a site at: http://vagrantbox.eswhich is a list of links to ba...
Vagrant Plugins
Vagrant PluginsVeeWee - https://github.com/jedi4ever/veeweeBuild custom base boxes from scratch.Includes templates for pop...
Vagrant Plugins
Vagrant PluginsVeeWee - https://github.com/jedi4ever/veewee$ veewee vbox define myubuntubox ubuntu-12.04-server-i386The ba...
Vagrant Plugins
Vagrant PluginsVeeWee - https://github.com/jedi4ever/veeweeHere, we can customise the build.- definition.rb - contains the ...
Vagrant Plugins
Vagrant PluginsVeeWee - https://github.com/jedi4ever/veeweeWe now build the box:$ veewee vbox build myubuntubox- Download’...
Vagrant Plugins
Vagrant PluginsVeeWee - https://github.com/jedi4ever/veeweeOnce the build is complete (takes some time), we can run some a...
Automated Provisioning (Configuration Management)
Automated Provisioning (Configuration Management)We’ve now got the ability to quickly spin up virtual machines as we requir...
Automated Provisioning (Configuration Management)
Automated Provisioning (Configuration Management)This also doesn’t just apply to development - what if we have tens or hund...
Automated Provisioning (Configuration Management)
Automated Provisioning (Configuration Management)This is where something called “Infrastructure as code” comes in.What if w...
Automated Provisioning (Configuration Management)
Automated Provisioning (Configuration Management)In the past, people would write shell scripts to do this. However, this is...
Automated Provisioning (Configuration Management)
Automated Provisioning (Configuration Management)Puppet:  Puppet Labs - founded by Luke Kanies in 2005.  Uses a declarative...
Automated Provisioning (Configuration Management)
Automated Provisioning (Configuration Management)Chef:    Opscode (2009)    Recipes written in pure Ruby.    Opscode provid...
Automated Provisioning (Configuration Management)
Automated Provisioning (Configuration Management)Both products can run in both a standalone mode or a client-server model -...
Automated Provisioning (Configuration Management)
Automated Provisioning (Configuration Management)Simple Puppet Example:$ mkdir manifestsIn the VagrantFile:config.vm.provis...
Automated Provisioning (Configuration Management)
Automated Provisioning (Configuration Management)Simple Puppet Example:In manifests/default.pp:class apache {    package { ...
Automated Provisioning (Configuration Management)
Automated Provisioning (Configuration Management)Simple Puppet Example:file { "/etc/apache/apache.conf":     owner => root,...
Automated Provisioning (Configuration Management)
Automated Provisioning (Configuration Management)Simple Puppet Example:  file { "/etc/apache2/sites-enabled/vagrantsite":  ...
More Information
More InformationVagrant:http://www.vagrantup.comGoogle Group: http://groups.google.com/group/vagrant-up#vagrant on irc.fre...
Upcoming SlideShare
Loading in...5
×

Virtualized development environments phpne - may 2012

17,341

Published on

A talk at PHP North East, 12th May 2012 - introduction to Virtualization, Vagrant, Configuration Management / Infrastructure as Code, Puppet and Chef...

Published in: Technology
0 Comments
10 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
17,341
On Slideshare
0
From Embeds
0
Number of Embeds
23
Actions
Shares
0
Downloads
71
Comments
0
Likes
10
Embeds 0
No embeds

No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Virtualized development environments phpne - may 2012

    1. 1. Virtualized DevelopmentEnvironments with Vagrant Ian Chilton PHP North East - 14th May 2012
    2. 2. IntroductionIan ChiltonBetter Brand Agencyhttp://www.betterbrandagency.comhttp://www.bettercommunities.co.ukTwitter: @ichiltonWeb: http://www.ichilton.co.ukLinkedIn: http://uk.linkedin.com/in/ichilton
    3. 3. Contents- Introduction to: - Development Environments - Virtualization- Why Virtualize your development environment?- Introduction to Vagrant- Using Vagrant- Vagrant Plugins- Automated Provisioning (Configuration Management)
    4. 4. Development Environments
    5. 5. Development EnvironmentsWe don’t want to be working on live sites.
    6. 6. Development EnvironmentsWe don’t want to be working on live sites.So we setup a development environment.
    7. 7. Development EnvironmentsWe don’t want to be working on live sites.So we setup a development environment.DEV StagingVCS LIVE
    8. 8. Development EnvironmentsWe don’t want to be working on live sites.So we setup a development environment. DEVDEV Staging Staging VCS DEVVCS LIVE LIVE DEV
    9. 9. Development Environments We don’t want to be working on live sites. So we setup a development environment. DEV DEV Staging Staging VCS DEV VCS LIVE LIVE DEVWe work on development, push/pullto/from version control and deploy tostaging and live.
    10. 10. Development Environments We don’t want to be working on live sites. So we setup a development environment. DEV DEV Staging Staging VCS DEV VCS LIVE LIVE DEVWe work on development, push/pullto/from version control and deploy tostaging and live. It’s DEV we’re going to be talking about here.
    11. 11. Development Environments
    12. 12. Development EnvironmentsNumber of (valid) ways:
    13. 13. Development EnvironmentsNumber of (valid) ways: - Copy of site (on live server) - Can easily affect the live site.
    14. 14. Development EnvironmentsNumber of (valid) ways: - Copy of site (on live server) - Can easily affect the live site. - Shared development server - Local / Remote / Dedicated / Cloud / VPS - Cost - Remote = latency / connection failure - Setup / management / maintenance - All developers and all projects sharing same hardware, software, versions etc.
    15. 15. Development Environments
    16. 16. Development EnvironmentsNumber of (valid) ways: - continued
    17. 17. Development EnvironmentsNumber of (valid) ways: - continued - Develop Locally: - MAMP (mac) or WAMP (windows) - Homebrew (mac), apt-get etc (linux) to install services locally
    18. 18. Development EnvironmentsNumber of (valid) ways: - continued - Develop Locally: - MAMP (mac) or WAMP (windows) - Homebrew (mac), apt-get etc (linux) to install services locally - Self sufficient - no remote latency / connection failure - However... - Clutter on workstation - Still shared between projects, set versions etc... - Different OS / platform / architecture
    19. 19. Development Environments
    20. 20. Development EnvironmentsConsider these scenarios (just some examples of many...)
    21. 21. Development EnvironmentsConsider these scenarios (just some examples of many...)The methods on the previous slides could install a different (mucholder or newer) version of a service like MySQL or PHP than theproduction box.You could then inadvertently code with something only added in alater version, or use something which had bugs in earlierversions.You’d there for have code which works in development but notwhen deployed to production.
    22. 22. Development Environments
    23. 23. Development EnvironmentsConsider these scenarios (just some examples of many...)
    24. 24. Development EnvironmentsConsider these scenarios (just some examples of many...)Both Windows and OS X use case insensitive filesystems.Imagine writing some code which used MyFile.txt.You could call this file myfile.txt and it would work on Windows/Mac.On Linux that would either error or be a completely different file.
    25. 25. Virtualization
    26. 26. VirtualizationSuch bugs can be very difficult and time consuming to track down.
    27. 27. VirtualizationSuch bugs can be very difficult and time consuming to track down.The lesson...We really need to develop on the same operatingsystem, architecture, package versions andconfiguration as production.
    28. 28. Virtualization
    29. 29. VirtualizationVirtualization is a technology where by a number of “virtualmachines” can be hosted on top of a single machine.
    30. 30. VirtualizationVirtualization is a technology where by a number of “virtualmachines” can be hosted on top of a single machine.The software running on the virtual machines (guests) is separatedfrom the software running on the “host”.
    31. 31. VirtualizationVirtualization is a technology where by a number of “virtualmachines” can be hosted on top of a single machine.The software running on the virtual machines (guests) is separatedfrom the software running on the “host”.The software used to make this possible is called a “hypervisor”.
    32. 32. VirtualizationVirtualization is a technology where by a number of “virtualmachines” can be hosted on top of a single machine.The software running on the virtual machines (guests) is separatedfrom the software running on the “host”.The software used to make this possible is called a “hypervisor”.This allows us to run different software on different virtual machines -for example you could run Windows and Linux virtual machines on aMac.
    33. 33. Types of VirtualizationFull VirtualizationAlmost complete simulation of the actual hardware.This allows the guest operating systems to run unmodified.Eg: - Oracle Virtualbox - Free virtualization product for the desktop - Cross platform - Windows, OS X, Linux - Lots of features - VMWare - Commercial (££) - Workstation and Server products
    34. 34. Types of VirtualizationParavirtualizationThe hardware environment is not simulated.The guest operating system is specially modified to allow thehypervisor to run the guests in their own isolated domain.Eg: - Xen which is used by: - Amazon EC2 - Rackspace Cloud - Some VPS providers
    35. 35. Types of VirtualizationHardware Assisted VirtualizationModern Intel or AMD CPU’s contain native virtualization functionalityon the CPU - Intel VT-x and AMD-V.Eg: - Linux KVM (Kernel Virtual Machine) which is used by: - Bytemark - Brightbox - VPS providers - Xen, Virtualbox & VMWare also support this as well, for hosts thathave the hardware support.
    36. 36. Types of VirtualizationOperating System Level Virtualization (aka. containers)The virtualization is implemented in software, on the host operatingsystem/kernel.The guest operating systems share the kernel of the host, but runthe guest operating system independently of the host.This allows isolated virtual machines and different distributions, butis generally limited to Unix based operating systems.Eg: - OpenVZ - LXC on Linux - FreeBSD jailsOften used by budget VPS providers as they can over-sell.
    37. 37. Advantages of Using Virtualization
    38. 38. Advantages of Using Virtualization- We can run the exact same operating system and setup as theproduction boxes, on top of any other machine, be it Mac, Windowsor Linux.- We can install the same software / packages / versions.- Everything is run in a contained sandbox and resources can bemanaged.- We can create distributable images to share.- If we run the VM’s locally, we can develop offline.
    39. 39. Disadvantages of Using Virtualization
    40. 40. Disadvantages of Using Virtualization- Many of the products we’ve mentioned require Linux (or anotherUNIX operating system) and don’t run on Mac or Windows.- Require searching around for operating system images or installingthe operating system on the VM manually.- Can be complicated/time consuming to learn, setup and configure.
    41. 41. Disadvantages of Using Virtualization- Many of the products we’ve mentioned require Linux (or anotherUNIX operating system) and don’t run on Mac or Windows.- Require searching around for operating system images or installingthe operating system on the VM manually.- Can be complicated/time consuming to learn, setup and configure.What we need is a simple and quick way ofbringing up virtual machines with minimal fuss.
    42. 42. VagrantCreated by Mitchell Hashimoto and John BenderCommand line interface/wrapper around Oracle’s free VirtualBoxsoftware (support for other hypervisors are in the works).Allows virtual machines to be created, inside of a minute, from pre-provided images, with a few simple commands. http://vagrantup.com
    43. 43. VagrantWe can use vagrant machines for:- Development- Testing- Experimenting new/different software/settings- Testing configuration management systems (explained later). http://vagrantup.com
    44. 44. Apprehensions
    45. 45. Apprehensions- Won’t it be slow? - Headless Linux VM’s aren’t as resource hungry as a Windowsvirtualized.- I want to use my local graphical editor... - Vagrant automatically creates a shared directory on the host.
    46. 46. Install Vagrant
    47. 47. Install Vagrant- Install Oracle Virtualbox (free from: http://virtualbox.org) - versionsfor Windows, Mac OS X or Linux. • Plus the extension pack.- Install Vagrant (free from: http://downloads.vagrantup.com)Still available as a Ruby gem but as of the recent v1.0, installers areprovided for Windows, Mac and Linux (deb and rpm).$ vagrant -vVagrant version 1.0.3
    48. 48. Base Boxes
    49. 49. Base BoxesPre-packaged operating system images.Official base boxes - Ubuntu LTS (long term support) releases.Ubuntu 10.04 (Lucid Lynx)$ vagrant box add lucid32 http://files.vagrantup.com/lucid32.box$ vagrant box add lucid64 http://files.vagrantup.com/lucid64.boxUbuntu 12.04 (Precise Pangolin):$ vagrant box add precise32 http://files.vagrantup.com/precise32.box$ vagrant box add precise64 http://files.vagrantup.com/precise64.box
    50. 50. Basic Vagrant Usage
    51. 51. Basic Vagrant Usage$ mkdir vagrant$ cd vagrant$ mkdir mydev$ cd mydevCreate a new config file (VagrantFile) for this instance:$ vagrant init lucid32Boot the machine (create from base box the 1st time):$ vagrant upSSH in:$ vagrant ssh
    52. 52. Basic Vagrant Usage
    53. 53. Basic Vagrant UsageVagrant automatically maps /vagrant inside the VM to the directoryon the host:vagrant@vagrant:~$ ls /vagrantindex.html VagrantfileCtrl-d exits the SSH session and takes us back to the host.Suspend the machine:$ vagrant suspend$ vagrant resumeShut down the machine:$ vagrant haltDestroy the machine:$ vagrant destroy
    54. 54. Vagrant Configuration
    55. 55. Vagrant ConfigurationThe “vagrant init” created a VagrantFile for this VM.Vagrant::Config.run do |config| config.vm.box = "lucid32"endWe can edit this to add additional options.
    56. 56. Vagrant Configuration
    57. 57. Vagrant ConfigurationGUI or Headless?:Vagrant::Config.run do |config| config.vm.box = "lucid32" # Boot with a GUI so you can see the screen. # (Default is headless) # config.vm.boot_mode = :guiend
    58. 58. Vagrant Configuration
    59. 59. Vagrant ConfigurationPort Forwarding:Vagrant::Config.run do |config| config.vm.box = "lucid32" # Map port 8080 on the host to port 80 in the VM: config.vm.forward_port 80, 8080end
    60. 60. Vagrant Configuration
    61. 61. Vagrant ConfigurationControl VirtualBox:Vagrant::Config.run do |config| config.vm.box = "lucid32" # Make the VM have 1GB RAM: config.vm.customize ["modifyvm", :id, "--memory", 1024]end
    62. 62. Vagrant Configuration
    63. 63. Vagrant ConfigurationMultiple Machines:Vagrant::Config.run do |config| # Web Server: config.vm.define :web do |web_config| web_config.vm.box = "web" web_config.vm.forward_port 80, 8080 end # Database Server: config.vm.define :db do |db_config| db_config.vm.box = "db" db_config.vm.forward_port 3306, 3306 endend
    64. 64. Vagrant Configuration
    65. 65. Vagrant ConfigurationNetworking:- Host Only - local communication between different VM’s. Vagrant::Config.run do |config| config.vm.box = "lucid32" config.vm.network :hostonly, “192.168.50.1” end- Bridged - bridge the VM onto the host’s network so we can access anythingon the network, and they can access the VM as if it was a normal machine onthe network. Vagrant::Config.run do |config| config.vm.box = "lucid32" config.vm.network :bridged end
    66. 66. Vagrant Configuration
    67. 67. Vagrant ConfigurationPackaging:Use as a starting point, or distribute instances.$ vagrant package --vagrantfile Vagrantfile.pkgThe --vagrantfile Vagrantfile.pkg option tells Vagrant to take the options placedin Vagrantfile.pkg and add them into the box so things like port forwarding willbe done automatically.We can then use this as normal:$ vagrant box add my_box /path/to/the/package.box$ vagrant init my_box$ vagrant up
    68. 68. Vagrant Plugins
    69. 69. Vagrant PluginsVagrant Box.es - Gareth Rushgrove has created a site at: http://vagrantbox.eswhich is a list of links to base boxes that people have built and made public(currently 49 boxes).He has also created a vagrant plugin to search, view and install them:https://github.com/garethr/ruby-vagrantboxesSahara - allow vagrant to run in a sandbox so any changes can be rolled back:https://github.com/jedi4ever/saharaVagrant Snap - allow snapshots and supports a multi vm environment:https://github.com/t9md/vagrant-snapVagrant Hosts - automatically update a dns server with vagrant hostnames:https://github.com/BerlinVagrant/vagrant-dnsVagrant plugin for Jenkins:http://unethicalblogger.com/2012/03/13/introducing-the-vagrant-plugin.html
    70. 70. Vagrant Plugins
    71. 71. Vagrant PluginsVeeWee - https://github.com/jedi4ever/veeweeBuild custom base boxes from scratch.Includes templates for popular distributions - CentOS, Debian, Fedora,ArchLinux, Gentoo, openSUSE, Ubuntu and even FreeBSD.
    72. 72. Vagrant Plugins
    73. 73. Vagrant PluginsVeeWee - https://github.com/jedi4ever/veewee$ veewee vbox define myubuntubox ubuntu-12.04-server-i386The basebox myubuntubox has been succesfully created fromthe template ubuntu-12.04-server-i386You can now edit the definition files stored in definitions/myubuntubox or build the box with:veewee vbox build myubuntubox$ ls definitions/myubuntuboxdefinition.rb postinstall.sh preseed.cfg
    74. 74. Vagrant Plugins
    75. 75. Vagrant PluginsVeeWee - https://github.com/jedi4ever/veeweeHere, we can customise the build.- definition.rb - contains the parameters for the box: cpu’s, memory, disk, O/S, ISO fileand url, boot sequence, SSH details etc.- preseed.cfg - This is the file the Debian/Ubuntu installer uses to automate theinstallation.- postinstall.sh - This is a shell script which is ran on the VM after the installation. In thiscase, it will: •Upgrade the O/S (apt-get update && apt-get dist-upgrade) •Install the dependancies for Ruby. •Install (or build from source) Ruby. •Install Puppet and Chef •Create a vagrant user and add in the standard Vagrant SSH public key into ~/.ssh/ authorized_keys.
    76. 76. Vagrant Plugins
    77. 77. Vagrant PluginsVeeWee - https://github.com/jedi4ever/veeweeWe now build the box:$ veewee vbox build myubuntubox- Download’s ISO the first time.- Starts a mini web server to serve the preseed.cfg file.- Creates a VirtualBox VM and boots the ISO.- At the boot prompt, it enters a custom boot prompt which points it to the urlfor the preseed.cfg.- The install complete’s automatically (using the preseed.cfg file) and veeweejust waits until it can successfully SSH to the VM.
    78. 78. Vagrant Plugins
    79. 79. Vagrant PluginsVeeWee - https://github.com/jedi4ever/veeweeOnce the build is complete (takes some time), we can run some automatedCucumber tests against the box:$ veewee vbox validate myubuntubox...7 scenarios (7 passed)21 steps (21 passed)0m14.810sThis checks the box is working and that Ruby, Ruby Gems, Chef, Puppet etcis responding as intended.If so, we can then build the box and add it into Vagrant:$ vagrant basebox export myubuntubox
    80. 80. Automated Provisioning (Configuration Management)
    81. 81. Automated Provisioning (Configuration Management)We’ve now got the ability to quickly spin up virtual machines as we requirethem.However, that only gets us a clean install - we’ve still got to start installingpackages and configuring things how we like them.If we are looking to share environments with colleagues etc, the problem withpre-packaged boxes/images is that they get out of date so they either have tobe periodically updated or extra steps added in whenever they are used.
    82. 82. Automated Provisioning (Configuration Management)
    83. 83. Automated Provisioning (Configuration Management)This also doesn’t just apply to development - what if we have tens or hundreds ofproduction servers?- How can we ensure that every time we setup a new server, all of the correct setup stepsare followed?- How can we ensure that the development, staging and production servers are all setupthe same.- What if we have a failure and it takes someone hours of running manual commands tobuild a new server? - what if a whole platform of tens or hundreds of servers fail?(connectivity or business)- How boring is it going to get for someone manually setting up servers?- We could document it, but will it be kept up-to-date?- What about maintaining the boxes on an ongoing basis? - how do we keep them up todate? when someone new starts, how long will it take to go round a lot of servers and addtheir user and ssh key or to apply a firewall change to all servers?
    84. 84. Automated Provisioning (Configuration Management)
    85. 85. Automated Provisioning (Configuration Management)This is where something called “Infrastructure as code” comes in.What if we were to do our server setup and management as we dodevelopment:- Write code (which also acts as documentation)- Put the code into version control so we can: - See and analyse changes, who made them and when. - Have branches and tags. - Easily roll back to old versions.- Run automated tests with Rspec and Cucumber to ensure everything isworking correctly without manually checking each server.- TDD - Test Driven DevelopmentThis ensures that server setup is consistent, reproducible, fast, mistake freeand automatable.
    86. 86. Automated Provisioning (Configuration Management)
    87. 87. Automated Provisioning (Configuration Management)In the past, people would write shell scripts to do this. However, this is difficultto manage and maintain.There are now a number of “configuration management” tools writtenspecifically for this purpose.The most popular and widely used of these is Puppet and Chef.
    88. 88. Automated Provisioning (Configuration Management)
    89. 89. Automated Provisioning (Configuration Management)Puppet: Puppet Labs - founded by Luke Kanies in 2005. Uses a declarative language to describe system configuration. Widely used and trusted by a number of large enterprise users - Wikimedia, Dell, Rackspace, Zynga, Twitter, New York Stock Exchange, Disney, Citrix, Oracle, Stanford University, Google and GovUK. James Turnbull (works for Puppet Labs) has written two books about Puppet which are published through Apress: - Pulling strings with Puppet - Pro Puppet -“Puppet 2.7 Cookbook” by John Arundel (Packtpub)
    90. 90. Automated Provisioning (Configuration Management)
    91. 91. Automated Provisioning (Configuration Management)Chef: Opscode (2009) Recipes written in pure Ruby. Opscode provides a “Hosted Chef” service to avoid running a local Chef server (like Github is to Git). Cookbooks - sharable! ! (although Puppet now has “Puppet Forge”) Knife - feature rich command line tool. Documentation improving: - Wiki - Stephen Nelson Smith, author of “Test Driven Infrastructure with Chef” is working on “Chef: The Definitive Guide” which is due to be published in September. - Podcast: http://www.foodfightshow.org/2012/03/episode-5-getting-started-with- chef.html
    92. 92. Automated Provisioning (Configuration Management)
    93. 93. Automated Provisioning (Configuration Management)Both products can run in both a standalone mode or a client-server model -Vagrant supports both of these.In the client/server model, the client will automatically “phone home” every sooften to check for changes.Idempotence:Run multiple times without affecting the result.i.e:- Instead of saying “Install Apache”, we say “Apache should be installed”.- Instead of “chown root.root myfile” we say “myfile should have this owner /group and these permissions.
    94. 94. Automated Provisioning (Configuration Management)
    95. 95. Automated Provisioning (Configuration Management)Simple Puppet Example:$ mkdir manifestsIn the VagrantFile:config.vm.provision :puppetORVagrant::Config.run do |config| config.vm.provision :puppet do |puppet| puppet.manifests_path = "manifests" puppet.manifest_file = "my_manifest.pp" endend
    96. 96. Automated Provisioning (Configuration Management)
    97. 97. Automated Provisioning (Configuration Management)Simple Puppet Example:In manifests/default.pp:class apache { package { "apache2": ensure => present, } service { "apache2": ensure => running, require => Package["apache2"], }}include apache
    98. 98. Automated Provisioning (Configuration Management)
    99. 99. Automated Provisioning (Configuration Management)Simple Puppet Example:file { "/etc/apache/apache.conf": owner => root, group => root, mode => 644, source => "puppet:////vagrant/puppet/files/apache.conf", require => Package["apache2"], notify => Service["apache2"] } file { "/etc/apache2/sites-available/vagrantsite": owner => root, group => root, mode => 644, source => "puppet:////vagrant/puppet/files/vhost.conf", require => Package["apache2"], notify => Service["apache2"] }
    100. 100. Automated Provisioning (Configuration Management)
    101. 101. Automated Provisioning (Configuration Management)Simple Puppet Example: file { "/etc/apache2/sites-enabled/vagrantsite": ensure => symlink, target => "/etc/apache2/sites-available/vagrantsite", require => Package["apache2"], notify => Service["apache2"] } file { "/etc/apache2/sites-enabled/default": ensure => absent, require => Package["apache2"], notify => Service["apache2"] }
    102. 102. More Information
    103. 103. More InformationVagrant:http://www.vagrantup.comGoogle Group: http://groups.google.com/group/vagrant-up#vagrant on irc.freenode.netPuppet:http://puppetlabs.com#puppet on irc.freenode.nethttp://www.puppetcookbook.comChef:http://www.opscode.com#chef on irc.feenode.netOther:http://devopsweekly.com
    1. A particular slide catching your eye?

      Clipping is a handy way to collect important slides you want to go back to later.

    ×