Portable Development Environments with Vagrant

719435d98d452de7ac367c828266cf01?s=47 Erika Heidi
September 19, 2014

Portable Development Environments with Vagrant

As presented at Hackference 2014

719435d98d452de7ac367c828266cf01?s=128

Erika Heidi

September 19, 2014
Tweet

Transcript

  1. None
  2. whoami • PHP developer with sysadmin background • Author of

    Vagrant Cookbook and phansible.com
  3. What to expect from this talk 1)Vagrant overview 2)Provisioning with

    Ansible 3)Useful Resources
  4. Why Vagrant?

  5. None
  6. 1.1 Why Vagrant? • Reproducible and portable development environment •

    Enables easier code collaboration • Backend env tests / benchmark • Automation Tools learning and testing
  7. None
  8. 1.2 Provisioning • Multiple provisioners can be used • Most

    common ones: – Puppet – Chef – Ansible – Shell Script
  9. Automation Tools > Shell Script • Right tool for the

    job • Clear language • Powerful built-in features • Provisioning can be reused for deployment
  10. 1.3 Some Terms • Host / Guest • Provider /

    Provisioner • Boxes • Vagrantfile • Synced Folder
  11. 1.4 The simplest thing that does something Vagrant.configure("2") do |config|

    config.vm.box = "hashicorp/precise64" config.vm.provision "shell", inline: "echo Hello World!" end
  12. None
  13. 1.5 Commands • up • reload • provision • suspend

    • resume • destroy [ --provision ] [ --provision ]
  14. 1.6 Other Vagrant Features • Managing Multiple VMs • Provisioning

    to AWS, Digital Ocean, etc • Vagrant Cloud • Vagrant Share / Connect
  15. DEMO 1 Vagrant up

  16. None
  17. 2.1 Ansible Overview • Simple and Powerful • Tasks defined

    with YAML • Sequential Execution • Modules Directory: Ansible Galaxy • Requires installation of Ansible in the Host
  18. 2.2 Vagrantfile Vagrant.configure("2") do |config| config.vm.box = "hashicorp/precise64" config.vm.provision "ansible"

    do |ansible| ansible.playbook = "playbook.yml" end end
  19. 2.3 The Playbook # playbook.yml --- - hosts: all sudo:

    true tasks: - name: Update apt-cache apt: update_cache=yes - name: Install Nginx apt: pkg=nginx state=latest
  20. 2.4 Playbook x Manifest (Puppet) #playbook.yml --- - hosts: all

    sudo: true tasks: - name: Update apt-cache apt: update_cache=yes - name: Install Nginx apt: pkg=nginx state=latest #default.pp exec { 'apt-get update': command => '/usr/bin/apt-get update' } package { 'nginx': ensure => "installed", require => Exec['apt-get update'], }
  21. 2.5 Variables --- - hosts: all sudo: yes vars: web_server:

    nginx tasks: - name: Install {{ web_server }} apt: pkg={{ web_server }} state=latest
  22. 2.5 Variables - arrays tasks: - name: Install Packages apt:

    pkg={{ item }} state=latest with_items: - nginx - php5-fpm - git
  23. 2.5 Variables - arrays --- - hosts: all sudo: yes

    vars: sys_packages: [ 'nginx', 'php5-fpm', 'git' ] tasks: - name: Install Packages apt: pkg={{ item }} state=latest with_items: sys_packages
  24. DEMO 2 Basic Playbook

  25. None
  26. None
  27. Vagrant Cookbook Special discount coupon for Hackference 2014 http://bit.ly/vc-hack

  28. Questions?

  29. More Vagrant Resources http://erikaheidi.com/vagrant