Slide 1

Slide 1 text

Build & Share Vagrant & Puppet development environments with Daniel Gomes @_dcsg 7 de Abril de 2014 Seminário

Slide 2

Slide 2 text

Who am I • Software Engineer @ UniPlaces • Co-founder & organizer @ phplx • Co-organizer @ SymfonyDay Portugal • ZCE PHP 5.3, CSM, OCP MySQL 5 Developer 2

Slide 3

Slide 3 text

@_dcsg Me on internet 3 dcsg danielcsgomes.com

Slide 4

Slide 4 text

Requirements • Vagrant 1.5.x • VirtualBox 4.3 • Git 4

Slide 5

Slide 5 text

Agenda • Introduction to Vagrant • Introduction to puppet • Hands on 5

Slide 6

Slide 6 text

Goals • Understand Vagrant and Puppet • Setup a dev environment 6

Slide 7

Slide 7 text

http://www.vagrantup.com/ 7

Slide 8

Slide 8 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 8

Slide 9

Slide 9 text

• 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, Ansible, Chef and other tools 9 What is Vagrant?

Slide 10

Slide 10 text

10 example of a Vagrantfile

Slide 11

Slide 11 text

11 # /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

Slide 12

Slide 12 text

12 $ cd /path/to/my/project ! $ vagrant up ! $ vagrant ssh Running it

Slide 13

Slide 13 text

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 13

Slide 14

Slide 14 text

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 14

Slide 15

Slide 15 text

Multi Machines Ability to replicate your system's architecture http://docs.vagrantup.com/v2/multi-machine/index.html 15

Slide 16

Slide 16 text

16 # /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

Slide 17

Slide 17 text

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 17

Slide 18

Slide 18 text

Debugging ! $ set VAGRANT_LOG=debug $ vagrant up ... http://docs.vagrantup.com/v2/debugging.html 18

Slide 19

Slide 19 text

Providers 19

Slide 20

Slide 20 text

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

Slide 21

Slide 21 text

Customize the Provider 21

Slide 22

Slide 22 text

22 # /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

Slide 23

Slide 23 text

Provision 23

Slide 24

Slide 24 text

24 Shell scripts

Slide 25

Slide 25 text

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

Slide 26

Slide 26 text

• IT automation software • Language inspired by Nagios • Declarative language 26 What is Puppet?

Slide 27

Slide 27 text

Basic concepts • Resources types • Classes, modules, templates • Variables, Facts and Conditionals • Ordering and chaining 27

Slide 28

Slide 28 text

Built-in Resources Types • File • Exec • Package • Cron • Host • Service • …. 28

Slide 29

Slide 29 text

File example file { "mod_actions_conf": path => "/etc/apache2/mods-enabled/actions.conf", ensure => "link", target => "/etc/apache2/mods-available/actions.conf" } 29

Slide 30

Slide 30 text

Classes • Named blocks • Defining a class does not evaluate the code • Declaring evaluates the code (include) 30 Modules • module name == folder name • specific folder structure

Slide 31

Slide 31 text

Class example class my_class { notify {"This actually did something":} } ! include my_class 31

Slide 32

Slide 32 text

Ordering & chaining • No loading order • before and require • notify and subscribe • arrow chaining ( -> to require and ~> to notify) 32

Slide 33

Slide 33 text

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 } } 33

Slide 34

Slide 34 text

http://www.ansible.com/home http://docs.ansible.com/ 34

Slide 35

Slide 35 text

• IT natural automation language • Agentless 35 What is Ansible?

Slide 36

Slide 36 text

Basic concepts • Inventory • Playbook • Tasks • Roles • Handlers • Modules 36

Slide 37

Slide 37 text

File example - name: Install custom repo yum: name=http://mirror.webtatic.com/yum/el6/latest.rpm state=present sudo: yes ! - name: Install common packages yum: name={{ item }} state=present sudo: yes with_items: - htop - vim 37

Slide 38

Slide 38 text

Inventory 38 Modules • module name == folder name • specific folder structure # /path/to/hosts [vagrant] 10.0.30.5 host1 ansible_ssh_port=5555 ansible_ssh_host=10.0.30.5

Slide 39

Slide 39 text

Class example class my_class { notify {"This actually did something":} } ! include my_class 39

Slide 40

Slide 40 text

Ordering & chaining • No loading order • before and require • notify and subscribe • arrow chaining ( -> to require and ~> to notify) 40

Slide 41

Slide 41 text

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 } } 41

Slide 42

Slide 42 text

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 42

Slide 43

Slide 43 text

let’s get started 43

Slide 44

Slide 44 text

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. 44

Slide 45

Slide 45 text

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 45

Slide 46

Slide 46 text

Librarian Puppet • Helps manage the modules • https://github.com/rodjek/librarian-puppet 46

Slide 47

Slide 47 text

PuPHPet A simple GUI to set up virtual machines for PHP Web development. 47 https://puphpet.com/ https://github.com/puphpet/puphpet

Slide 48

Slide 48 text

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/ 48

Slide 49

Slide 49 text

@danielcsgomes | [email protected] | http://danielcsgomes.com Jian Awe © http://www.flickr.com/photos/qqjawe/6511141237 Questions? https://joind.in/9281 rate & feedback 49