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

Portable Development Environments with Vagrant

Erika Heidi
September 19, 2014

Portable Development Environments with Vagrant

As presented at Hackference 2014

Erika Heidi

September 19, 2014
Tweet

More Decks by Erika Heidi

Other Decks in Programming

Transcript

  1. 1.1 Why Vagrant? • Reproducible and portable development environment •

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

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

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

    Provisioner • Boxes • Vagrantfile • Synced Folder
  5. 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
  6. 1.5 Commands • up • reload • provision • suspend

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

    to AWS, Digital Ocean, etc • Vagrant Cloud • Vagrant Share / Connect
  8. 2.1 Ansible Overview • Simple and Powerful • Tasks defined

    with YAML • Sequential Execution • Modules Directory: Ansible Galaxy • Requires installation of Ansible in the Host
  9. 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
  10. 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'], }
  11. 2.5 Variables --- - hosts: all sudo: yes vars: web_server:

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

    pkg={{ item }} state=latest with_items: - nginx - php5-fpm - git
  13. 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