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

Empower your team with Vagrant and Puppet - wor...

Empower your team with Vagrant and Puppet - workshop

One of the tasks that developers spend most of they time is getting their development environment working properly.

This task is hard as well for the new team members. Vagrant is a tool that lets you manage Virtual Machines in a simple way by using a single configuration file.

Puppet is a tool that lets you provision the Virtual Machine, this means, it allows you to install packages, execute commands, create folders, create users and do any administrative task inside the Virtual Machine with a simple configuration file.

Vagrant with Puppet allows you to create your development environment and easily share with your teammats. This workshop will introduce you into Vagrant and Puppet and at the end you will have a real development environment working and you will learn how to share it.

This workshop was given @ The Startup Scholarship 2013 edition

Daniel Gomes

July 15, 2013
Tweet

More Decks by Daniel Gomes

Other Decks in Technology

Transcript

  1. AGENDA • Why is distributed environment a good thing •

    Introduction to Vagrant • Introduction to Puppet • Building a distributed development environment 2
  2. 3 ABOUT ME • Full Stack Web Developer @ Sedimap

    PT • Father, Geek • Zend Certi!ed Engineer PHP 5.3 • Certi!ed Scrum Master • @danielcsgomes
  3. “I use unix” “I use Windows” “You need to change

    to project B” “Your code does not work in my machine” “I need to install an older version of software y” “New team member? Install all this stu"” “Need to reinstall everything again” “I’m tired to con!gure it over and over again” “Lost one day to con!gure my machine” 7
  4. 10 What if "does not work on my machine" ?

    you could get rid of the quote
  5. va•grant (ˈveɪ grənt) Noun: a person without a settled home

    or regular work who wanders from place to place and lives by begging DEFINITION 15
  6. What is Vagrant? • Manage virtual machines (such as Virtual

    Box, VMware, AWS) • Define the configuration in code using a single file • Can use Shell scripts, Puppet, Chef and other tools to provisioning the Virtual Machines • Written in Ruby 16
  7. Workflow of vagrant up 26 Vagrantfile Provisioning manifest has provisioning

    manifest? yes start provisioning the VM VM is running vagrant up downloads the box if needed and loads vagrant configurations (share folders, port forwarding, etc) and starts the VM
  8. 28 # Vagrantfile Vagrant.configure("2") do |config| config.vm.box = "precise64" config.vm.box_url

    = "http://files.vagrantup.com/precise64.box" # port forwarding config.vm.network :forwarded_port, guest: 80, host: 8080 # setup a private network with a static IP Address # nfs requires a static IP address config.vm.network :private_network, ip: "10.5.0.2" # sharing folders # Vagrant 1.1+ automatically ignores nfs on Windows OS config.vm.synced_folder ".", "/vagrant", :nfs => true end
  9. 29 # Vagrantfile Vagrant.configure("2") do |config| config.vm.box = "precise64" config.vm.box_url

    = "http://files.vagrantup.com/precise64.box" # port forwarding config.vm.network :forwarded_port, guest: 80, host: 8080 # setup a private network with a static IP Address # nfs requires a static IP address config.vm.network :private_network, ip: "10.5.0.2" # sharing folders # Vagrant 1.1+ automatically ignores nfs on Windows OS config.vm.synced_folder ".", "/vagrant", :nfs => true end
  10. 30 # Vagrantfile Vagrant.configure("2") do |config| config.vm.box = "precise64" config.vm.box_url

    = "http://files.vagrantup.com/precise64.box" # port forwarding config.vm.network :forwarded_port, guest: 80, host: 8080 # setup a private network with a static IP Address # nfs requires a static IP address config.vm.network :private_network, ip: "10.5.0.2" # sharing folders # Vagrant 1.1+ automatically ignores nfs on Windows OS config.vm.synced_folder ".", "/vagrant", :nfs => true end
  11. 31 # Vagrantfile Vagrant.configure("2") do |config| config.vm.box = "precise64" config.vm.box_url

    = "http://files.vagrantup.com/precise64.box" # port forwarding config.vm.network :forwarded_port, guest: 80, host: 8080 # setup a private network with a static IP Address # nfs requires a static IP address config.vm.network :private_network, ip: "10.5.0.2" # sharing folders # Vagrant 1.1+ automatically ignores nfs on Windows OS config.vm.synced_folder ".", "/vagrant", :nfs => true end
  12. 32 # Vagrantfile Vagrant.configure("2") do |config| config.vm.box = "precise64" config.vm.box_url

    = "http://files.vagrantup.com/precise64.box" # port forwarding config.vm.network :forwarded_port, guest: 80, host: 8080 # setup a private network with a static IP Address # nfs requires a static IP address config.vm.network :private_network, ip: "10.5.0.2" # sharing folders # Vagrant 1.1+ automatically ignores nfs on Windows OS config.vm.synced_folder ".", "/vagrant", :nfs => true end
  13. vagrant init vagrant up vagrant halt vagrant reload vagrant provision

    vagrant ssh vagrant suspend vagrant resume vagrant destroy 33 vagrant commands
  14. 34 vagrant init vagrant up vagrant halt vagrant reload vagrant

    provision vagrant ssh vagrant suspend vagrant resume vagrant destroy vagrant init Initializes Vagrant
  15. 35 vagrant init vagrant up vagrant halt vagrant reload vagrant

    provision vagrant ssh vagrant suspend vagrant resume vagrant destroy vagrant up Create and configure the Virtual Machine
  16. 36 vagrant halt Shutdown the Virtual Machine vagrant init vagrant

    up vagrant halt vagrant reload vagrant provision vagrant ssh vagrant suspend vagrant resume vagrant destroy
  17. 37 vagrant reload Restart the Virtual Machine vagrant init vagrant

    up vagrant halt vagrant reload vagrant provision vagrant ssh vagrant suspend vagrant resume vagrant destroy
  18. 38 vagrant provision Provision a started Virtual Machine vagrant init

    vagrant up vagrant halt vagrant reload vagrant provision vagrant ssh vagrant suspend vagrant resume vagrant destroy
  19. 39 vagrant ssh Access the Virtual Machine via SSH in

    *unix Outputs the SSH configuration in Windows vagrant init vagrant up vagrant halt vagrant reload vagrant provision vagrant ssh vagrant suspend vagrant resume vagrant destroy
  20. 40 vagrant suspend Suspends the Virtual Machine vagrant init vagrant

    up vagrant halt vagrant reload vagrant provision vagrant ssh vagrant suspend vagrant resume vagrant destroy
  21. 41 vagrant resume Resume a suspended Virtual Machine vagrant init

    vagrant up vagrant halt vagrant reload vagrant provision vagrant ssh vagrant suspend vagrant resume vagrant destroy
  22. 42 vagrant destroy Delete the created Virtual Machine vagrant init

    vagrant up vagrant halt vagrant reload vagrant provision vagrant ssh vagrant suspend vagrant resume vagrant destroy
  23. http://docs.vagrantup.com/v2/virtualbox/configuration.html 48 # Vagranfile Vagrant.configure("2") do |config| config.vm.box = "precise64"

    config.vm.box_url = "http://files.vagrantup.com/precise64.box" config.vm.network :forwarded_port, guest: 80, host: 8080 config.vm.network :private_network, ip: "10.5.0.2" config.vm.synced_folder ".", "/vagrant", :nfs => true config.vm.provider "virtualbox" do |vb| vb.name = "phplx" # custom VM name vb.gui = true # enables GUI, defaults is false # Vagrant exposes a way to call any command against VBoxManage # Example: Change the memory of the VM vb.customize ["modifyvm", :id, "--memory", "512"] end end
  24. http://docs.vagrantup.com/v2/virtualbox/configuration.html 49 # Vagranfile Vagrant.configure("2") do |config| config.vm.box = "precise64"

    config.vm.box_url = "http://files.vagrantup.com/precise64.box" config.vm.network :forwarded_port, guest: 80, host: 8080 config.vm.network :private_network, ip: "10.5.0.2" config.vm.synced_folder ".", "/vagrant", :nfs => true config.vm.provider "virtualbox" do |vb| vb.name = "phplx" # custom VM name vb.gui = true # enables GUI, defaults is false # Vagrant exposes a way to call any command against VBoxManage # Example: Change the memory of the VM vb.customize ["modifyvm", :id, "--memory", "512"] end end
  25. http://docs.vagrantup.com/v2/virtualbox/configuration.html 50 # Vagranfile Vagrant.configure("2") do |config| config.vm.box = "precise64"

    config.vm.box_url = "http://files.vagrantup.com/precise64.box" config.vm.network :forwarded_port, guest: 80, host: 8080 config.vm.network :private_network, ip: "10.5.0.2" config.vm.synced_folder ".", "/vagrant", :nfs => true config.vm.provider "virtualbox" do |vb| vb.name = "phplx" # custom VM name vb.gui = true # enables GUI, defaults is false # Vagrant exposes a way to call any command against VBoxManage # Example: Change the memory of the VM vb.customize ["modifyvm", :id, "--memory", "512"] end end
  26. http://docs.vagrantup.com/v2/virtualbox/configuration.html 51 # Vagranfile Vagrant.configure("2") do |config| config.vm.box = "precise64"

    config.vm.box_url = "http://files.vagrantup.com/precise64.box" config.vm.network :forwarded_port, guest: 80, host: 8080 config.vm.network :private_network, ip: "10.5.0.2" config.vm.synced_folder ".", "/vagrant", :nfs => true config.vm.provider "virtualbox" do |vb| vb.name = "phplx" # custom VM name vb.gui = true # enables GUI, defaults is false # Vagrant exposes a way to call any command against VBoxManage # Example: Change the memory of the VM vb.customize ["modifyvm", :id, "--memory", "512"] end end
  27. http://docs.vagrantup.com/v2/virtualbox/configuration.html 52 # Vagranfile Vagrant.configure("2") do |config| config.vm.box = "precise64"

    config.vm.box_url = "http://files.vagrantup.com/precise64.box" config.vm.network :forwarded_port, guest: 80, host: 8080 config.vm.network :private_network, ip: "10.5.0.2" config.vm.synced_folder ".", "/vagrant", :nfs => true config.vm.provider "virtualbox" do |vb| vb.name = "phplx" # custom VM name vb.gui = true # enables GUI, defaults is false # Vagrant exposes a way to call any command against VBoxManage # Example: Change the memory of the VM vb.customize ["modifyvm", :id, "--memory", "512"] end end
  28. What is Puppet? • Declarative and model-based approach to IT

    automation • Performs administrative tasks (such as adding users, create folders, installing packages, etc) • Cross OS • Written in Ruby 54
  29. 56 # Vagrantfile Vagrant.configure("2") do |config| config.vm.box = "precise64" config.vm.box_url

    = "http://files.vagrantup.com/precise64.box" config.vm.network :forwarded_port, guest: 80, host: 8080 config.vm.network :private_network, ip: "10.5.0.2" config.vm.synced_folder ".", "/vagrant", :nfs => true config.vm.provision :puppet do |puppet| puppet.manifests_path = "vagrant/puppet" puppet.manifest_file = "init.pp" # defines the puppet modules folder puppet.module_path = "vagrant/modules" # set puppet options puppet.options = [ '--verbose', '--debug' ] end end
  30. 57 # Vagrantfile Vagrant.configure("2") do |config| config.vm.box = "precise64" config.vm.box_url

    = "http://files.vagrantup.com/precise64.box" config.vm.network :forwarded_port, guest: 80, host: 8080 config.vm.network :private_network, ip: "10.5.0.2" config.vm.synced_folder ".", "/vagrant", :nfs => true config.vm.provision :puppet do |puppet| puppet.manifests_path = "vagrant/puppet" puppet.manifest_file = "init.pp" # defines the puppet modules folder puppet.module_path = "vagrant/modules" # set puppet options puppet.options = [ '--verbose', '--debug' ] end end
  31. 59 # vagrant/puppet/init.pp class apt_update { exec { "aptGetUpdate": command

    => "sudo apt-get update", path => ["/bin", "/usr/bin"] } } class os_tools { package { "curl": ensure => present, require => Exec["aptGetUpdate"] } } include apt_update include os_tools
  32. 60 # vagrant/puppet/init.pp class apt_update { exec { "aptGetUpdate": command

    => "sudo apt-get update", path => ["/bin", "/usr/bin"] } } class os_tools { package { "curl": ensure => present, require => Exec["aptGetUpdate"] } } include apt_update include os_tools
  33. 61 # vagrant/puppet/init.pp class apt_update { exec { "aptGetUpdate": command

    => "sudo apt-get update", path => ["/bin", "/usr/bin"] } } class os_tools { package { "curl": ensure => present, require => Exec["aptGetUpdate"] } } include apt_update include os_tools
  34. 62 # vagrant/puppet/init.pp class apt_update { exec { "aptGetUpdate": command

    => "sudo apt-get update", path => ["/bin", "/usr/bin"] } } class os_tools { package { "curl": ensure => present, require => Exec["aptGetUpdate"] } } include apt_update include os_tools
  35. • Use (D)VCS (Git, SVN, Mercurial, etc.) • Add the

    Vagrantfile and provisioning files (puppet, chef, shell scripts, etc) to your repository • Add .vagrant folder to your repository ignore file or your global ignore file. 66
  36. • When working in multiple projects use port forwarding and

    networks carefully • Avoid port collision by adding auto_correct: true for each port forwarding • Use --debug on your provision options when something is wrong • Have guest additions always up to date • Improve share folders performance by enabling nfs (is not available on windows) • You can prevent vagrant from running provision using vagrant up --no-provision • Use vewee tool to create base boxes • If you are using Puppet modules, don't forget to add the module dependencies as well Tips and Tricks 67
  37. • Sharing your dev environment saves you time and makes

    your life easier and everyone happy • Vagrant manages the Virtual Machines using a configuration file • Default provider is Virtual Box, but VMware and AWS are available too • Vagrant can provision the VM using Puppet, Chef, Shell scripts or other tools Wrap up 68
  38. RESOURCES • Documentation • Vagrant - http://docs.vagrantup.com/v2/ • Puppet -

    http://docs.puppetlabs.com/references/latest/type.html • Chef - http://docs.opscode.com/chef/index.html • Ansible - http://ansible.cc/docs/ • Vewee - https://github.com/jedi4ever/veewee • Downloads • Vagrant - http://downloads.vagrantup.com/ • Virtual Box - https://www.virtualbox.org/wiki/Downloads • VMware - http://www.vmware.com/products/player/ • Source code of the talk demos - http://goo.gl/UgsDi • List of base boxes - http://www.vagrantbox.es/ 69