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

Portable Environments with Vagrant

Portable Environments with Vagrant

Portable Development Environments with Vagrant (and Ansible) - LaraconEU 2014

Erika Heidi

August 29, 2014
Tweet

More Decks by Erika Heidi

Other Decks in Programming

Transcript

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

    Vagrant Cookbook on LeanPub and phansible.com
  2. 1.1 Why Vagrant? • Reproducible and portable development environment •

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

    common ones: – Puppet – Chef – Ansible – Shell Script
  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. 2.1 Ansible Overview • Simple and Powerful • Tasks defined

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

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

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