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

ZendCon Europe | Building a LAMP environment with Vagrant & Puppet

0fe2d959c89cf2d9de497a237c4ea99d?s=47 Daniel Gomes
November 18, 2013

ZendCon Europe | Building a LAMP environment with Vagrant & Puppet

Do you work in more than one project or with more than one person in or per project? If yes, this workshop 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 workshop will introduce you to Vagrant and Puppet. You will build your own dev environment step-by-step and at the end you will know how to share it and how you can reproduce and customize it for other projects.

Source code is available here: http://goo.gl/vWt3Sa

0fe2d959c89cf2d9de497a237c4ea99d?s=128

Daniel Gomes

November 18, 2013
Tweet

More Decks by Daniel Gomes

Other Decks in Programming

Transcript

  1. A LAMP environment Vagrant and Puppet from the ground up

    with Daniel Gomes @danielcsgomes November 18, 2013 workshop
  2. Who am I • Software Engineer @ GuestCentric Systems •

    Co-founder & organizer @ phplx • Father of a beautiful boy • ZCE PHP 5.3, CSM, OCP MySQL 5 Developer !2
  3. @danielcsgomes Follow me !3

  4. Requirements • Vagrant 1.3.5 • VirtualBox 4.3 • Git !4

  5. Agenda • Introduction to Vagrant and puppet • Build a

    Lamp environment • Distribute and share your environment !5
  6. Goals • Understand Vagrant and Puppet • Setup a LAMP

    dev environment • Customize it for your needs • AWS? !6
  7. Requirements • Git • Virtual Box 4.3 • Vagrant 1.3.5

    !7
  8. http://www.vagrantup.com/ !8

  9. 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 !9
  10. • Manage virtual machines (such as Virtual Box, VMware, AWS,

    and others) • Define the configuration in code with a single file • Provision the VM with Shell scripts, Puppet, Chef and other tools !10 What is Vagrant?
  11. !11 example of a Vagrantfile

  12. !12 # /path/to/Vagrantfile ! Vagrant.configure("2") do |config| ! # define

    base box 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 config.vm.network :private_network, ip: "10.5.0.2" ! # sharing folders config.vm.synced_folder ".", "/vagrant" ! end
  13. !13 $ cd /path/to/my/project ! $ vagrant up ! $

    vagrant ssh Running it
  14. Workflow of vagrant up Vagrantfile Provision manifest has provisioning manifest

    and it’s first time? yes start provisioning the VM VM is running vagrant up downloads the box if needed, loads the vagrant configuration (share folders, port forwarding, etc) and starts the VM !14
  15. vagrant init vagrant up vagrant halt vagrant reload vagrant provision

    vagrant package vagrant plugin vagrant ssh vagrant ssh-config vagrant suspend vagrant resume vagrant destroy vagrant commands !15
  16. Multi Machines Ability to replicate your system's architecture http://docs.vagrantup.com/v2/multi-machine/index.html !16

  17. !17 # /path/to/Vagrantfile ! Vagrant.configure("2") do |config| ! config.vm.define "web"

    do |web| web.vm.box = "apache" # ... end ! config.vm.define "db" do |db| db.vm.box = "mysql" # ... end ! end
  18. Plugins https://github.com/mitchellh/vagrant/wiki/Available-Vagrant-Plugins vagrant plugin install vagrant-example-plugin vagrant plugin list vagrant

    plugin uninstall vagrant-example-plugin Installing a plugin Uninstalling a plugin Listing installed plugin !18
  19. Debugging ! $ set VAGRANT_LOG=debug $ vagrant up ... http://docs.vagrantup.com/v2/debugging.html

    !19
  20. Providers !20

  21. and others… https://github.com/mitchellh/vagrant/wiki/Available-Vagrant-Plugins#providers !21

  22. Customize the Provider !22

  23. !23 # /path/to/Vagrantfile ! Vagrant.configure("2") do |config| ! config.vm.provider :virtualbox

    do |vb| vb.customize [ "modifyvm", :id, '--chipset', 'ich9', '--natdnshostresolver1', 'on', '--memory', 1024 ] end ! end
  24. Provision !24

  25. !25 Shell scripts Ansible

  26. http://puppetlabs.com/ http://docs.puppetlabs.com/references/latest/type.html !26

  27. • IT automation software • Language inspired by Nagios •

    Declarative language !27 What is Puppet?
  28. Basic concepts • Resources types • Classes, modules, templates •

    Variables, Facts and Conditionals • Ordering and chaining !28
  29. Built-in Resources Types • File • Exec • Package •

    Cron • Host • Service • …. !29
  30. File example file { "mod_actions_conf": path => "/etc/apache2/mods-enabled/actions.conf", ensure =>

    "link", target => "/etc/apache2/mods-available/actions.conf" } !30
  31. Classes • Named blocks • Defining a class does not

    evaluate the code • Declaring evaluates the code (include) !31 Modules • module name == folder name • specific folder structure
  32. Class example class my_class { notify {"This actually did something":}

    } ! include my_class !32
  33. Ordering & chaining • No loading order • before and

    require • notify and subscribe • arrow chaining ( -> to require and ~> to notify) !33
  34. Ordering example class apt { exec { "apt-update": unless =>

    "test -f /home/vagrant/.apt-update", command => "apt-get update -y", path => ["/bin", "/usr/bin"], notify => File["/home/vagrant/.apt-update"], } ! file { "/home/vagrant/.apt-update": ensure => file, force => true } } !34
  35. What are we going to build? ! • Provider: Virtual

    box 4.3 • OS: Ubuntu 12.04 x64 ! • PHP 5.4 • Apache 2.2 • MySQL 5.5 !35
  36. let’s get started !36

  37. Distributing and sharing • 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. !37
  38. Tips and Tricks • 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) • If you are using Puppet modules, don't forget to add the module dependencies as well !38
  39. Librarian Puppet • Helps manage the modules • https://github.com/rodjek/librarian-puppet !39

  40. PuPHPet A simple GUI to set up virtual machines for

    PHP Web development. !40 https://puphpet.com/ https://github.com/puphpet/puphpet
  41. Resources • Documentation • Vagrant - http://docs.vagrantup.com/v2/ • Puppet -

    http://docs.puppetlabs.com/references/latest/type.html • Learning Puppet - http://docs.puppetlabs.com/learning/index.html • Chef - http://docs.opscode.com/chef/index.html • Ansible - http://ansible.cc/docs/ • Vewee - https://github.com/jedi4ever/veewee • Packer - http://www.packer.io/ ! • 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/vWt3Sa • List of base boxes - http://www.vagrantbox.es/ !41
  42. @danielcsgomes | me@danielcsgomes.com | http://danielcsgomes.com Jian Awe © http://www.flickr.com/photos/qqjawe/6511141237 Questions?

    https://joind.in/9281 rate & feedback !42