Share
Embed
Boost your dev environment with Vagrant
Do you work in more than one project or with more than one person in or per project? If yes, this talk is for you.
One of the tasks where developers usually spend lots of time is in the configuration of the project development environment. What if you configure it by running a simple command? Without to have to hurry about product versions, without install anything in your machine?
This talk will be an introduction to Vagrant with Puppet that let’s you distribute your development environment. I will use a pratical example to explain and demonstrate how Vagrant and Puppet works.
Vagrant is a tool that manages virtual machines under VirtualBox or VMware. The virtual machines can be provisioning with bash scritps, puppet or chef.
Daniel Gomes
June 13, 2013
Transcript
93 slides
-
Boost with Vagrant your dev environment Daniel Gomes @danielcsgomes June
12, 2013 europeanspaceagency © http://www.flickr.com/photos/europeanspaceagency/3704205848 -
AGENDA • Why is distributed environment a good thing •
Why and what is Vagrant? • Providers • Provisioning with Puppet 2 -
3 ABOUT ME • Full Stack Web Developer @ Sedimap
PT • Father, Geek • Zend Certi!ed Engineer PHP 5.3 • Certi!ed Scrum Master • @danielcsgomes -
“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 -
HOW 8 MANY TIMES DID IT HAPPEN TO YOU?! sometimes
suzie ©: http://www.flickr.com/photos/22324124@N07/6186059907 -
10 What if of your co-workers? you have the same
environment -
12 What if "does not work on my machine" ?
you could get rid of the quote -
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 23 -
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 24 -
How does it work? Will assume you already have Vagrant
and a provider installed in your machine (will use Virtual Box because it’s free) 25 http://downloads.vagrantup.com/tags/v1.2.2 https://www.virtualbox.org/wiki/Downloads -
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 -
28 $ cd /path/to/my/project $ vagrant init precise64 http://files.vagrantup.com/precise64.box $
tree . └── Vagrantfile $ vagrant up $ vagrant ssh -
29 $ cd /path/to/my/project $ vagrant init precise64 http://files.vagrantup.com/precise64.box $
tree . └── Vagrantfile $ vagrant up $ vagrant ssh -
30 $ cd /path/to/my/project $ vagrant init precise64 http://files.vagrantup.com/precise64.box $
tree . └── Vagrantfile $ vagrant up $ vagrant ssh -
31 $ cd /path/to/my/project $ vagrant init precise64 http://files.vagrantup.com/precise64.box $
tree . └── Vagrantfile $ vagrant up $ vagrant ssh -
32 $ cd /path/to/my/project $ vagrant init precise64 http://files.vagrantup.com/precise64.box $
tree . └── Vagrantfile $ vagrant up $ vagrant ssh -
33 $ cd /path/to/my/project $ vagrant init precise64 http://files.vagrantup.com/precise64.box $
tree . └── Vagrantfile $ vagrant up $ vagrant ssh -
36 # 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 -
37 # 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 -
38 # 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 -
39 # 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 -
40 # 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 -
vagrant init vagrant up vagrant halt vagrant reload vagrant provision
vagrant ssh vagrant suspend vagrant resume vagrant destroy 42 vagrant commands -
43 vagrant init vagrant up vagrant halt vagrant reload vagrant
provision vagrant ssh vagrant suspend vagrant resume vagrant destroy vagrant init Initializes Vagrant -
44 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 -
45 vagrant halt Shutdown the Virtual Machine vagrant init vagrant
up vagrant halt vagrant reload vagrant provision vagrant ssh vagrant suspend vagrant resume vagrant destroy -
46 vagrant reload Restart the Virtual Machine vagrant init vagrant
up vagrant halt vagrant reload vagrant provision vagrant ssh vagrant suspend vagrant resume vagrant destroy -
47 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 -
48 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 -
49 vagrant suspend Suspends the Virtual Machine vagrant init vagrant
up vagrant halt vagrant reload vagrant provision vagrant ssh vagrant suspend vagrant resume vagrant destroy -
50 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 -
51 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 -
http://docs.vagrantup.com/v2/virtualbox/configuration.html 57 # 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 -
http://docs.vagrantup.com/v2/virtualbox/configuration.html 58 # 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 -
http://docs.vagrantup.com/v2/virtualbox/configuration.html 59 # 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 -
http://docs.vagrantup.com/v2/virtualbox/configuration.html 60 # 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 -
http://docs.vagrantup.com/v2/virtualbox/configuration.html 61 # 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 -
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 64 -
68 # 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 # Vagrant will look inside the "manifests" folder # for the default manifest file "default.pp" config.vm.provision :puppet end -
69 # 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 # Vagrant will look inside the "manifests" folder # for the default manifest file "default.pp" config.vm.provision :puppet end -
71 # 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| # to the manifests folder puppet.manifests_path = "vagrant/puppet" # initial manifest puppet.manifest_file = "init.pp" end end -
72 # 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| # to the manifests folder puppet.manifests_path = "vagrant/puppet" # initial manifest puppet.manifest_file = "init.pp" end end -
73 # 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| # to the manifests folder puppet.manifests_path = "vagrant/puppet" # initial manifest puppet.manifest_file = "init.pp" end end -
74 # 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| # to the manifests folder puppet.manifests_path = "vagrant/puppet" # initial manifest puppet.manifest_file = "init.pp" end end -
Vagrant with puppet 75 modules and options configuration puppet modules
- http://docs.puppetlabs.com/puppet/2.7/reference/modules_fundamentals.html vagrant docs for puppet provisioning - http://docs.vagrantup.com/v2/provisioning/puppet_apply.html -
76 # 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 -
77 # 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 -
78 # 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 -
80 # 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 -
81 # 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 -
82 # 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 -
83 # 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 -
• 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. 87 -
• 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 88 -
90 step !ve a real world use case Demo of
• Ubuntu 12.04 • Apache 2.2 • MySQL 5.5 • PHP 5.4 https://github.com/danielcsgomes/boost-your-dev-environment-with-vagrant/tree/step-five -
• 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 Sum up 91 -
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/s1WnR • List of base boxes - http://www.vagrantbox.es/ 92 -
@danielcsgomes | [email protected] | http://danielcsgomes.com Jian Awe © http://www.#ickr.com/photos/qqjawe/6511141237 Please
give feedback: http://goo.gl/3WcWw Questions?