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

Virtualize your development environments with Vagrant & Puppet

crohr
May 14, 2012

Virtualize your development environments with Vagrant & Puppet

This talk is about using Vagrant & Puppet to easily provision virtual machines that can be used as isolated development environments for your projects. You'll keep your development machine fast, your environments isolated, and any developer will be able to get up and running on a new project in less than 5 minutes.

crohr

May 14, 2012
Tweet

More Decks by crohr

Other Decks in Programming

Transcript

  1. Vagrant & Puppet Virtualize your development environments with La Cantine

    Numérique - 14 May 2012 @RennesOnRails @RennesDevops 1
  2. Why virtualize? Multiple projects + Dependencies on various kinds of

    software in various degrees of stability = Your development machine is becoming full of crap 4
  3. Why virtualize? Multiple projects + Dependencies on the same software

    but with different versions = Your development machine is becoming full of crap (again) 5
  4. Why virtualize? Existing developer with (partial and not up to

    date) info on how to reproduce a development environment + New developer on the team (with a shiny new machine) = Issues to reproduce the same development environment 6
  5. $ git clone git://path/to/my-app.git $ cd my-app && bundle install

    $ magic-command $ rake db:setup $ rake test # or rails server What if? 9
  6. $ git clone git://path/to/my-app.git $ cd my-app && bundle install

    $ vagrant up $ rake db:setup $ rake test # or rails server What if? 10
  7. Abstracts away the nitty-gritty details of the VirtualBox API, and

    more! Vagrant $ vagrant box add $ vagrant init $ vagrant up $ vagrant provision $ vagrant ssh $ vagrant suspend $ vagrant destroy $ vagrant package 13
  8. Vagrantfile Vagrant - port forwarding - shared folders - VM

    configuration (RAM) - network configuration - SSH access ... 14 Vagrant::Config.run do |config| config.vm.box = "squeeze-x64" config.vm.box_url = "http://files.crohr.me/vagrant/debian- squeeze-x64-puppet-v4.1.12.box" config.vm.customize ["modifyvm", :id, "--memory", 512] # config.vm.boot_mode = :gui # config.vm.network :hostonly, "192.168.33.10" # config.vm.network :bridged config.vm.forward_port 3306, 13306 config.vm.forward_port 6379, 16379 config.vm.share_folder "id", "/vagrant_data", "../data" # Enable provisioning with Puppet stand alone. config.vm.provision :puppet, :module_path => "puppet/ modules" do |puppet| puppet.manifests_path = "puppet/manifests" puppet.manifest_file = "my-app.pp" end end
  9. for project in A B C; do cd $project vagrant

    up ... hack ... vagrant suspend done Vagrant 15
  10. No GUI, can be fully automated. Think about it like

    this boxes vagrant up/resume vagrant halt/suspend 16
  11. DSL to describe your environment configuration http://puppetlabs.com/ Puppet class redis($bind_address

    = "127.0.0.1") { package {"redis-server": ensure => installed } service {"redis-server": ensure => running, require => Package["redis-server"] } file { "/etc/redis/redis.conf": mode => 644, owner => root, group => root, content => template("redis/redis.conf.erb"), notify => Service["redis-server"], require => Package["redis-server"]; } } http://docs.puppetlabs.com/references/stable/type.html 18
  12. Installs & configures according to the recipe Puppet [default] Running

    Puppet with /tmp/vagrant-puppet/manifests/my-app.pp... notice: /Stage[main]/Redis/Package[redis-server]/ensure: ensure changed 'purged' to 'present' notice: /Stage[main]/Redis/File[/etc/redis/redis.conf]/content: content changed '{md5} a19bad63017ec19def2c3a8a07bdc362' to '{md5}2e7b4b6e37a56dd0c8c1b7573cff2bce' notice: /Stage[main]/Redis/Service[redis-server]: Triggered 'refresh' from 1 events notice: /Stage[main]//Package[mysql-server]/ensure: ensure changed 'purged' to 'present' notice: /Stage[main]//File[/etc/mysql/conf.d/custom.cnf]/ensure: defined content as '{md5} aea46f45d8499176de3cb888405788f2' notice: /Stage[main]//Service[mysqld]: Triggered 'refresh' from 1 events notice: /Stage[main]//Exec[add-mysql-user]/returns: executed successfully 19
  13. Supported in Vagrant Puppet # Vagrantfile config.vm.provision :puppet, :module_path =>

    "puppet/modules" do |puppet| puppet.manifests_path = "puppet/manifests" puppet.manifest_file = "my-app.pp" end 20
  14. - Download and install VirtualBox. - Install Ruby on your

    machine. - $ gem install vagrant http://rvm.io/ Recap’ http://virtualbox.org/ 22
  15. $ git clone git://github.com/ crohr/vagrant-presentation.git $ cd vagrant-presentation $ bundle

    install $ vagrant up $ rake db:setup $ rails server Recap’ 23
  16. Profit! 24 • Isolate development environments from each other •

    Decrease the time it takes for a developer to get up and running on a new project (this applies for you as well if you lose or crash your development machine) • Increase your chance of successful deployments by mirroring the production environment • Reuse your Puppet or Chef recipes in production and development environments • Keep your development machine small and fast
  17. • Create your own base boxes http://vagrantup.com/docs/base_boxes.html • Share your

    base boxes http://vagrantbox.es/ • Multi-VM configuration http://vagrantup.com/docs/multivm.html • Use it on your CI server! ex: http://travis-ci.org/ https://wiki.jenkins-ci.org/display/JENKINS/Vagrant+Plugin • Extend with plugins http://vagrantup.com/docs/plugins.html Going further 25