Pro Yearly is on sale from $80 to $50! »

Portable Environments with Vagrant

Portable Environments with Vagrant

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

719435d98d452de7ac367c828266cf01?s=128

Erika Heidi

August 29, 2014
Tweet

Transcript

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

    Vagrant Cookbook on LeanPub 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. 1.3 Some Terms • Host / Guest • Provider /

    Provisioner • Boxes • Vagrantfile • Synced Folder
  10. 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
  11. None
  12. 1.5 Commands • up • reload • provision • suspend

    • resume • destroy [ --provision ] [ --provision ]
  13. DEMO 1 Vagrant up

  14. None
  15. 2.1 Ansible Overview • Simple and Powerful • Tasks defined

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

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

    pkg={{ item }} state=latest with_items: - nginx - php5-fpm - git
  21. 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
  22. DEMO 2 Basic Playbook

  23. None
  24. None
  25. Vagrant Cookbook Special discount coupon for Laracon EU 2014 http://bit.ly/vc-laracon

  26. Questions?

  27. More Vagrant Resources http://erikaheidi.com/vagrant Please Rate this Talk! https://joind.in/11689