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. 1.
  2. 5.
  3. 6.

    1.1 Why Vagrant? • Reproducible and portable development environment •

    Enables easier code collaboration • Backend env tests / benchmark • Automation Tools learning and testing
  4. 7.
  5. 8.

    1.2 Provisioning • Multiple provisioners can be used • Most

    common ones: – Puppet – Chef – Ansible – Shell Script
  6. 9.

    Automation Tools > Shell Script • Right tool for the

    job • Clear language • Powerful built-in features • Provisioning can be reused for deployment
  7. 10.

    1.3 Some Terms • Host / Guest • Provider /

    Provisioner • Boxes • Vagrantfile • Synced Folder
  8. 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
  9. 12.
  10. 13.

    1.5 Commands • up • reload • provision • suspend

    • resume • destroy [ --provision ] [ --provision ]
  11. 14.

    1.6 Other Vagrant Features • Managing Multiple VMs • Provisioning

    to AWS, Digital Ocean, etc • Vagrant Cloud • Vagrant Share / Connect
  12. 16.
  13. 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
  14. 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
  15. 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'], }
  16. 21.

    2.5 Variables --- - hosts: all sudo: yes vars: web_server:

    nginx tasks: - name: Install {{ web_server }} apt: pkg={{ web_server }} state=latest
  17. 22.

    2.5 Variables - arrays tasks: - name: Install Packages apt:

    pkg={{ item }} state=latest with_items: - nginx - php5-fpm - git
  18. 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
  19. 25.
  20. 26.