$30 off During Our Annual Pro Sale. View Details »

DRIVE with Vagrant and Ansible

Erika Heidi
November 19, 2015

DRIVE with Vagrant and Ansible

As presented at php[world] 2015

Erika Heidi

November 19, 2015
Tweet

More Decks by Erika Heidi

Other Decks in Programming

Transcript

  1. View Slide

  2. DRIVE with Vagrant and Ansible
    @erikaheidi / PHP[world] 2015
    whoami

    View Slide

  3. DRIVE with Vagrant and Ansible
    @erikaheidi / PHP[world] 2015
    Back to 2006...

    View Slide

  4. DRIVE with Vagrant and Ansible
    @erikaheidi / PHP[world] 2015
    PHP Development Environments

    View Slide

  5. DRIVE with Vagrant and Ansible
    @erikaheidi / PHP[world] 2015
    Sharing the Project

    View Slide

  6. DRIVE with Vagrant and Ansible
    @erikaheidi / PHP[world] 2015
    Deployment

    View Slide

  7. DRIVE with Vagrant and Ansible
    @erikaheidi / PHP[world] 2015
    Hosting

    View Slide

  8. DRIVE with Vagrant and Ansible
    @erikaheidi / PHP[world] 2015
    Now back to 2015...

    View Slide

  9. DRIVE with Vagrant and Ansible
    @erikaheidi / PHP[world] 2015
    What a time to be alive!

    View Slide

  10. DRIVE with Vagrant and Ansible
    @erikaheidi / PHP[world] 2015
    But, still...
    “It works on my machine”

    View Slide

  11. DRIVE with Vagrant and Ansible
    @erikaheidi / PHP[world] 2015
    What if I told you...

    View Slide

  12. DRIVE with Vagrant and Ansible
    @erikaheidi / PHP[world] 2015
    What if I told you...
    There's a way to make your development
    process more consistent, while also
    smoothing the transition from dev to prod?

    View Slide

  13. DRIVE with Vagrant and Ansible
    @erikaheidi / PHP[world] 2015
    Presenting: D.R.I.V.E

    Disposable

    Replicable

    Isolated

    Versioned

    Environment

    View Slide

  14. DRIVE with Vagrant and Ansible
    @erikaheidi / PHP[world] 2015
    Presenting: D.R.I.V.E

    Disposable

    Replicable

    Isolated

    Versioned

    Environment

    View Slide

  15. DRIVE with Vagrant and Ansible
    @erikaheidi / PHP[world] 2015
    D.R.I.V.E
    Disposable &
    Isolated
    Replicable &
    Versioned

    View Slide

  16. DRIVE with Vagrant and Ansible
    @erikaheidi / PHP[world] 2015
    D.R.I.V.E
    Disposable &
    Isolated

    Virtual Machines,
    Containers
    Replicable &
    Versioned

    View Slide

  17. DRIVE with Vagrant and Ansible
    @erikaheidi / PHP[world] 2015
    D.R.I.V.E
    Disposable &
    Isolated

    Virtual Machines,
    Containers
    – VirtualBox, VMWare,
    KVM, etc
    – Docker
    Replicable &
    Versioned

    View Slide

  18. DRIVE with Vagrant and Ansible
    @erikaheidi / PHP[world] 2015
    D.R.I.V.E
    Disposable &
    Isolated

    Virtual Machines,
    Containers
    – VirtualBox, VMWare,
    KVM, etc
    – Docker
    Replicable &
    Versioned

    Configuration
    Management

    View Slide

  19. DRIVE with Vagrant and Ansible
    @erikaheidi / PHP[world] 2015
    D.R.I.V.E
    Disposable &
    Isolated

    Virtual Machines,
    Containers
    – VirtualBox, VMWare,
    KVM, etc
    – Docker
    Replicable &
    Versioned

    Configuration
    Management
    – Ansible, Puppet, Chef,
    Salt, etc

    View Slide

  20. DRIVE with Vagrant and Ansible
    @erikaheidi / PHP[world] 2015
    VAGRANT

    View Slide

  21. DRIVE with Vagrant and Ansible
    @erikaheidi / PHP[world] 2015
    Vagrant

    Virtual Machines +
    Configuration Management

    Easy DRIVE for DEV

    Made Conf. Management
    popular with developers
    – And we nailed it!

    View Slide

  22. DRIVE with Vagrant and Ansible
    @erikaheidi / PHP[world] 2015
    Otto?

    View Slide

  23. DRIVE with Vagrant and Ansible
    @erikaheidi / PHP[world] 2015
    Otto?
    "Otto is very young and while we tout it as a
    successor to Vagrant, it'll take time to reach the
    maturity level that Vagrant is already at. We
    don't recommend dropping Vagrant today, but
    look to Otto for the future.."

    View Slide

  24. DRIVE with Vagrant and Ansible
    @erikaheidi / PHP[world] 2015
    How Vagrant Works

    View Slide

  25. DRIVE with Vagrant and Ansible
    @erikaheidi / PHP[world] 2015
    The Vagrantfile
    Vagrant.configure("2") do |config|
    config.vm.box = "ubuntu/trusty64"
    config.vm.network "forwarded_port", guest: 80,
    host: 8080
    config.vm.synced_folder "/vagrant", "."
    config.vm.provision "shell", inline: "echo hello"
    end

    View Slide

  26. DRIVE with Vagrant and Ansible
    @erikaheidi / PHP[world] 2015
    This whole provisioning thing...

    View Slide

  27. DRIVE with Vagrant and Ansible
    @erikaheidi / PHP[world] 2015
    ANSIBLE

    View Slide

  28. DRIVE with Vagrant and Ansible
    @erikaheidi / PHP[world] 2015
    Ansible

    Simple and straightforward
    language (YAML)

    Agentless Architecture

    Huge collection of built-in modules

    Great community, very popular on Github - 13k+
    stars and almost 4k forks

    View Slide

  29. DRIVE with Vagrant and Ansible
    @erikaheidi / PHP[world] 2015
    Playbook Example
    ---
    - hosts: all
    sudo: true
    tasks:
    - name: Update apt-cache
    apt: update_cache=yes
    - name: Install Nginx
    apt: pkg=nginx state=latest

    View Slide

  30. DRIVE with Vagrant and Ansible
    @erikaheidi / PHP[world] 2015
    Playbook Resources

    Variables

    Loops

    Conditionals

    Templates

    Ansible Vault

    View Slide

  31. DRIVE with Vagrant and Ansible
    @erikaheidi / PHP[world] 2015
    LET'S DRIVE?

    View Slide

  32. DRIVE with Vagrant and Ansible
    @erikaheidi / PHP[world] 2015
    Vagrantfile
    #Vagrantfile
    Vagrant.configure("2") do |config|
    config.vm.box = "ubuntu/trusty64"
    config.vm.network "forwarded_port", guest: 80,
    host: 8080
    config.vm.provision "ansible" do |ansible|
    ansible.playbook = "demo.yml"
    end
    end

    View Slide

  33. DRIVE with Vagrant and Ansible
    @erikaheidi / PHP[world] 2015
    Playbook
    ---
    - hosts: all
    sudo: true
    vars:
    packages: ["nginx", "php5-fpm"]
    tasks:
    - name: Update apt-cache
    apt: update_cache=yes
    - name: Install Packages
    apt: pkg={{ item }} state=latest
    with_items: packages
    - name: Change Nginx Vhost File
    template: src=default.tpl dest=/etc/nginx/sites-available/default
    notify: restart nginx
    handlers:
    - name: restart nginx
    service: name=nginx enabled=yes state=restarted

    View Slide

  34. DRIVE with Vagrant and Ansible
    @erikaheidi / PHP[world] 2015
    DEMO

    View Slide

  35. DRIVE with Vagrant and Ansible
    @erikaheidi / PHP[world] 2015
    when this baby hits 88 mph...

    View Slide

  36. DRIVE with Vagrant and Ansible
    @erikaheidi / PHP[world] 2015
    TIPS&TRICKS

    View Slide

  37. DRIVE with Vagrant and Ansible
    @erikaheidi / PHP[world] 2015
    1. Roles
    .
    ├── playbook.yml
    └── roles
    ├── init
    │ └── tasks
    │ └── main.yml
    └── webserver
    ├── handlers
    │ └── main.yml
    ├── tasks
    │ └── main.yml
    └── templates
    └── vhost.tpl
    #playbook.yml
    ---
    - hosts: all
    sudo: true
    vars:
    doc_root: /vagrant/web
    roles:
    - init
    - webserver

    View Slide

  38. DRIVE with Vagrant and Ansible
    @erikaheidi / PHP[world] 2015
    2. Phansible

    View Slide

  39. DRIVE with Vagrant and Ansible
    @erikaheidi / PHP[world] 2015
    2. Phansible
    .
    ├── ansible
    │ ├── inventories
    │ │ └── dev
    │ ├── playbook.yml
    │ ├── roles
    │ │ ├── app
    │ │ ├── mysql
    │ │ ├── nginx
    │ │ ├── php
    │ │ ├── server
    │ │ └── vagrant_local
    │ └── vars
    │ └── all.yml
    └── Vagrantfile

    View Slide

  40. DRIVE with Vagrant and Ansible
    @erikaheidi / PHP[world] 2015
    2. Phansible
    .
    ├── ansible
    │ ├── inventories
    │ │ └── dev
    │ ├── playbook.yml
    │ ├── roles
    │ │ ├── app
    │ │ ├── mysql
    │ │ ├── nginx
    │ │ ├── php
    │ │ ├── server
    │ │ └── vagrant_local
    │ └── vars
    │ └── all.yml
    └── Vagrantfile
    #inventories/dev
    [phansible-web]
    192.168.33.10

    View Slide

  41. DRIVE with Vagrant and Ansible
    @erikaheidi / PHP[world] 2015
    3. group_vars
    .
    ├── ansible
    │ ├── inventories
    │ │ ├── dev
    │ │ ├── test
    │ │ └── prod
    │ ├── group_vars
    │ │ ├── all.yml
    │ │ ├── web-dev.yml
    │ │ ├── web-prod.yml
    │ │ └── web-test.yml
    │ ├── playbook.yml
    │ ├── roles
    │ └── windows.sh
    └── Vagrantfile

    View Slide

  42. DRIVE with Vagrant and Ansible
    @erikaheidi / PHP[world] 2015
    3. group_vars
    .
    ├── ansible
    │ ├── inventories
    │ │ ├── dev
    │ │ ├── test
    │ │ └── prod
    │ ├── group_vars
    │ │ ├── all.yml
    │ │ ├── web-dev.yml
    │ │ ├── web-prod.yml
    │ │ └── web-test.yml
    │ ├── playbook.yml
    │ ├── roles
    │ └── windows.sh
    └── Vagrantfile
    #inventories/prod
    [web-prod]
    myapp.io

    View Slide

  43. DRIVE with Vagrant and Ansible
    @erikaheidi / PHP[world] 2015
    3. group_vars
    .
    ├── ansible
    │ ├── inventories
    │ │ ├── dev
    │ │ ├── test
    │ │ └── prod
    │ ├── group_vars
    │ │ ├── all.yml
    │ │ ├── web-dev.yml
    │ │ ├── web-prod.yml
    │ │ └── web-test.yml
    │ ├── playbook.yml
    │ ├── roles
    │ └── windows.sh
    └── Vagrantfile
    #group_vars/web-prod.yml
    project_root: /var/www
    doc_root: /var/www/web
    sys_packages: ["vim","fail2ban"]
    #inventories/prod
    [web-prod]
    myapp.io

    View Slide

  44. DRIVE with Vagrant and Ansible
    @erikaheidi / PHP[world] 2015
    3. group_vars
    .
    ├── ansible
    │ ├── inventories
    │ │ ├── dev
    │ │ ├── test
    │ │ └── prod
    │ ├── group_vars
    │ │ ├── all.yml
    │ │ ├── web-dev.yml
    │ │ ├── web-prod.yml
    │ │ └── web-test.yml
    │ ├── playbook.yml
    │ ├── roles
    │ └── windows.sh
    └── Vagrantfile
    #group_vars/web-prod.yml
    project_root: /var/www
    doc_root: /var/www/web
    sys_packages: ["vim","fail2ban"]
    #inventories/prod
    [web-prod]
    myapp.io
    bit.ly/multistage

    View Slide

  45. DRIVE with Vagrant and Ansible
    @erikaheidi / PHP[world] 2015
    4. ansible-vault
    $ ansible-vault encrypt group_vars/web-prod.yml
    twitter:
    app_token: MYSUPERTOKEN
    app_secret: MYSUPERSECRET
    otherthing:
    secret_thing: SECRET
    secret_other: TOPSECRET
    $ANSIBLE_VAULT;1.1;AES256
    39356166303165393330613634373636
    61343834313564386262323234303063
    3539656138633837
    32353631303265623232306338303266
    65306531633835630a36306133306539
    3835356331343862
    32346132653432623766366161333334
    66393964396261303637313335646463
    before after

    View Slide

  46. DRIVE with Vagrant and Ansible
    @erikaheidi / PHP[world] 2015
    4. ansible-vault
    $ ansible-playbook (…) --ask-vault-pass
    $ ansible-vault view path/to/varfile.yml
    $ ansible-vault edit path/to/varfile.yml

    View Slide

  47. DRIVE with Vagrant and Ansible
    @erikaheidi / PHP[world] 2015

    View Slide

  48. DRIVE with Vagrant and Ansible
    @erikaheidi / PHP[world] 2015
    Vagrant Cookbook
    leanpub.com/vagrantcookbook/c/phpworld

    View Slide

  49. DRIVE with Vagrant and Ansible
    @erikaheidi / PHP[world] 2015
    QUESTIONS?

    View Slide

  50. DRIVE with Vagrant and Ansible
    @erikaheidi / PHP[world] 2015
    Please rate the
    talks you attend!

    View Slide

  51. DRIVE with Vagrant and Ansible
    @erikaheidi / PHP[world] 2015
    THANKS!

    View Slide