Slide 1

Slide 1 text

Empower Vagrant and Puppet your team with Daniel Gomes @danielcsgomes July 13, 2013 workshop

Slide 2

Slide 2 text

AGENDA • Why is distributed environment a good thing • Introduction to Vagrant • Introduction to Puppet • Building a distributed development environment 2

Slide 3

Slide 3 text

3 ABOUT ME • Full Stack Web Developer @ Sedimap PT • Father, Geek • Zend Certi!ed Engineer PHP 5.3 • Certi!ed Scrum Master • @danielcsgomes

Slide 4

Slide 4 text

4 Why is distributed environment a good thing?

Slide 5

Slide 5 text

5 let's see...

Slide 6

Slide 6 text

6 http://xkcd.com/349/

Slide 7

Slide 7 text

“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

Slide 8

Slide 8 text

8 What if development environment? all the team have the same

Slide 9

Slide 9 text

9 What if customize and share it? you could replicate,

Slide 10

Slide 10 text

10 What if "does not work on my machine" ? you could get rid of the quote

Slide 11

Slide 11 text

11 EnterpriseMobility © http://www.#ickr.com/photos/entmobility/5140252625/ how

Slide 12

Slide 12 text

12 Distributing environment your development image source © FreeDigitalPhotos.net

Slide 13

Slide 13 text

13 with

Slide 14

Slide 14 text

http://www.vagrantup.com/ 14

Slide 15

Slide 15 text

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

Slide 16

Slide 16 text

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

Slide 17

Slide 17 text

17 Why Vagrant?

Slide 18

Slide 18 text

Is portable and easy to share 18

Slide 19

Slide 19 text

Reproducible and customizable 19

Slide 20

Slide 20 text

Virtualized and isolated 20

Slide 21

Slide 21 text

Allows you to work close to your production environment 21

Slide 22

Slide 22 text

and makes your life easier and everyone happy 22

Slide 23

Slide 23 text

Requirements 23 • Vagrant - http://downloads.vagrantup.com/tags/v1.2.2 • Virtual Box - https://www.virtualbox.org/wiki/Downloads

Slide 24

Slide 24 text

use vagrant 24 how to

Slide 25

Slide 25 text

25 $ cd /path/to/my/project $ vagrant init precise64 http://files.vagrantup.com/precise64.box $ tree . └── Vagrantfile $ vagrant up $ vagrant ssh Demo

Slide 26

Slide 26 text

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

Slide 27

Slide 27 text

Vagrantfile 27 Example of

Slide 28

Slide 28 text

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

Slide 29

Slide 29 text

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

Slide 30

Slide 30 text

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

Slide 31

Slide 31 text

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

Slide 32

Slide 32 text

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

Slide 33

Slide 33 text

vagrant init vagrant up vagrant halt vagrant reload vagrant provision vagrant ssh vagrant suspend vagrant resume vagrant destroy 33 vagrant commands

Slide 34

Slide 34 text

34 vagrant init vagrant up vagrant halt vagrant reload vagrant provision vagrant ssh vagrant suspend vagrant resume vagrant destroy vagrant init Initializes Vagrant

Slide 35

Slide 35 text

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

Slide 36

Slide 36 text

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

Slide 37

Slide 37 text

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

Slide 38

Slide 38 text

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

Slide 39

Slide 39 text

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

Slide 40

Slide 40 text

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

Slide 41

Slide 41 text

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

Slide 42

Slide 42 text

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

Slide 43

Slide 43 text

Providers 43

Slide 44

Slide 44 text

default vagrant provider http://docs.vagrantup.com/v2/virtualbox/configuration.html 44 and it's free

Slide 45

Slide 45 text

available, but’s not free http://www.vagrantup.com/vmware 45

Slide 46

Slide 46 text

and other providers are available, using vagrant plugin system http://docs.vagrantup.com/v2/plugins/providers.html 46

Slide 47

Slide 47 text

Virtual Box machine 47 Customize on Vagrantfile

Slide 48

Slide 48 text

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

Slide 49

Slide 49 text

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

Slide 50

Slide 50 text

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

Slide 51

Slide 51 text

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

Slide 52

Slide 52 text

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

Slide 53

Slide 53 text

http://puppetlabs.com/ 53 http://docs.puppetlabs.com/references/latest/type.html

Slide 54

Slide 54 text

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

Slide 55

Slide 55 text

Vagrant and puppet 55

Slide 56

Slide 56 text

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

Slide 57

Slide 57 text

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

Slide 58

Slide 58 text

Puppet manifest 58

Slide 59

Slide 59 text

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

Slide 60

Slide 60 text

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

Slide 61

Slide 61 text

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

Slide 62

Slide 62 text

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

Slide 63

Slide 63 text

63 Building a distributed development environment

Slide 64

Slide 64 text

64 The development environment: • Ubuntu 12.04 • NodeJS 0.10.12 • MongoDB 2.4.5 http://goo.gl/UgsDi

Slide 65

Slide 65 text

65 how to share your environment?

Slide 66

Slide 66 text

• 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

Slide 67

Slide 67 text

• 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

Slide 68

Slide 68 text

• 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

Slide 69

Slide 69 text

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

Slide 70

Slide 70 text

@danielcsgomes | [email protected] | http://danielcsgomes.com Jian Awe © http://www.#ickr.com/photos/qqjawe/6511141237 Questions?