Slide 1

Slide 1 text

No content

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

Hi, I’m Thijs

Slide 4

Slide 4 text

I’m @ThijsFeryn on Twitter

Slide 5

Slide 5 text

I’m an at Evangelist

Slide 6

Slide 6 text

I’m a at board member

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

Create and configure lightweight, reproducible, and portable development environments.

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

Why? Why? Why?

Slide 12

Slide 12 text

•Environment per project •Dev ~= Test ~= Staging ~= Prod •Easy to define & transport •Easy to tear down •Provisionable: infrastructure as code •Versionable •Shared across the team

Slide 13

Slide 13 text

Vagrantfile Vagrant box vagrant up How Vagrant works Provisioning scripts VM’s on your computer

Slide 14

Slide 14 text

Generate a Vagrantfile $  vagrant  init  ubuntu/trusty64

Slide 15

Slide 15 text

•Select base box •Choose virtualization provider •Configure VM parameters •Configure networking •Tweak SSH settings •Mount local folders •Provision machine What does a Vagrantfile do?

Slide 16

Slide 16 text

Vagrant.configure(2)  do  |config|            config.vm.box  =  "ubuntu/trusty64"            config.vm.network  "forwarded_port",  guest:  80,  host:  8080      config.vm.network  "private_network",  ip:  "192.168.33.10"      config.vm.network  "public_network"      config.vm.synced_folder  "./www",  "/var/www"      config.vm.provider  "virtualbox"  do  |vb|          vb.memory  =  "1024"          vb.cpus  =  "4"        end      config.vm.provision  "ansible"  do  |ansible|                  ansible.playbook  =  "ansible/playbook.yml"      end   end

Slide 17

Slide 17 text

Boxes

Slide 18

Slide 18 text

http://vagrantcloud.com Search for public boxes Official

Slide 19

Slide 19 text

http://www.packer.io Build your own boxes

Slide 20

Slide 20 text

https://docs.vagrantup.com/ v2/boxes/base.html Or do it manually

Slide 21

Slide 21 text

http://atlas.hashicorp.com Host your boxes in the Cloud

Slide 22

Slide 22 text

Manage boxes $  vagrant  box  add  hashicorp/precise64   $  vagrant  box  add  precise32  http:// files.vagrantup.com/precise32.box  -­‐-­‐provider   virtualbox   $  vagrant  box  list   $  vagrant  box  remove  hashicorp/precise64   $  vagrant  box  repackage  precise32  virtualbox  0   $  vagrant  box  outdated   $  vagrant  box  update   $  vagrant  package

Slide 23

Slide 23 text

Vagrant.configure("2")  do  |config|      config.vm.box  =  "ubuntu/trusty64"   end Vagrantfile can do this too Vagrant.configure("2")  do  |config|      config.vm.box  =  "precise32"      config.vm.box_url  =  "http:// files.vagrantup.com/precise32.box"       end URL for self-hosted boxes

Slide 24

Slide 24 text

Vagrant up & running

Slide 25

Slide 25 text

•vagrant up •vagrant suspend •vagrant halt •vagrant reload •vagrant destroy •vagrant status

Slide 26

Slide 26 text

Connect

Slide 27

Slide 27 text

vagrant ssh

Slide 28

Slide 28 text

•Passwordless login •SSH keys •Generated on vagrant up •Private key in .vagrant folder of your project •Public key in authorized_keys file for vagrant user

Slide 29

Slide 29 text

vagrant ssh-config Host  default      HostName  127.0.0.1      User  vagrant      Port  2202      UserKnownHostsFile  /dev/null      StrictHostKeyChecking  no      PasswordAuthentication  no      IdentityFile  /Users/thijs/Sites/ vagrantup/.vagrant/machines/default/ virtualbox/private_key      IdentitiesOnly  yes      LogLevel  FATAL

Slide 30

Slide 30 text

Networking

Slide 31

Slide 31 text

Vagrant.configure(2)  do  |config|            config.vm.box  =  "ubuntu/trusty64"            config.vm.network  "forwarded_port",  guest:  80,  host:  8080      config.vm.network  "private_network",  ip:  "192.168.33.10"      config.vm.network  "public_network"   end Networking

Slide 32

Slide 32 text

Synced folders

Slide 33

Slide 33 text

By default your project folder is mounted as /vagrant on the guest VM

Slide 34

Slide 34 text

Vagrant.configure(2)  do  |config|            config.vm.box  =  "ubuntu/trusty64"            config.vm.network  "forwarded_port",  guest:  80,  host:  8080      config.vm.network  "private_network",  ip:  "192.168.33.10"      config.vm.network  “public_network"      config.vm.synced_folder  "./www",  "/var/www"   end Synced folders

Slide 35

Slide 35 text

VM properties

Slide 36

Slide 36 text

Vagrant.configure(2)  do  |config|            config.vm.box  =  "ubuntu/trusty64"            config.vm.network  "forwarded_port",  guest:  80,  host:  8080      config.vm.network  "private_network",  ip:  "192.168.33.10"      config.vm.network  "public_network"      config.vm.synced_folder  "./www",  "/var/www"      config.vm.provider  "virtualbox"  do  |vb|          vb.memory  =  "1024"          vb.cpus  =  "4"        end   end VM properties

Slide 37

Slide 37 text

Portability

Slide 38

Slide 38 text

Who the hell cares about an empty Linux box?

Slide 39

Slide 39 text

Provisioning

Slide 40

Slide 40 text

•File •Shell •Ansible •Cfengine •Chef Solo •Chef Zero •Chef Client •Chef Apply •Docker •Puppet Apply •Puppet Agent •Salt Provisioning

Slide 41

Slide 41 text

No content

Slide 42

Slide 42 text

•Configuration management •Simple/lightweight •Yaml •Config > code •Written in Python •Standalone/agentless •Pushes commands over SSH •Lots of modules •Lots of public “roles”

Slide 43

Slide 43 text

Vagrant.configure(2)  do  |config|            config.vm.box  =  "ubuntu/trusty64"            config.vm.network  "forwarded_port",  guest:  80,  host:  8080      config.vm.network  "private_network",  ip:  "192.168.33.10"      config.vm.network  "public_network"      config.vm.synced_folder  "./www",  "/var/www"      config.vm.provider  "virtualbox"  do  |vb|          vb.memory  =  "1024"          vb.cpus  =  "4"        end      config.vm.provision  "ansible"  do  |ansible|                  ansible.playbook  =  "ansible/playbook.yml"      end   end Ansible provisioning in Vagrant

Slide 44

Slide 44 text

-­‐-­‐-­‐   -­‐  hosts:  all      vars:          docroot:  /vagrant/www          servername:  mysite.dev      sudo:  yes      tasks:      -­‐  name:  ensure  nginx  is  at  the  latest  version          apt:  pkg=nginx  state=latest      -­‐  name:  write  the  nginx  config  file          template:  src=mysite.conf.j2  dest=/etc/nginx/sites-­‐ enabled/mysite.conf          notify:          -­‐  restart  nginx      -­‐  name:  ensure  nginx  is  running  (and  enable  it  at  boot)          service:  name=nginx  state=started  enabled=yes      handlers:          -­‐  name:  restart  nginx              service:  name=nginx  state=restarted Simple playbook example

Slide 45

Slide 45 text

-­‐-­‐-­‐   -­‐  hosts:  all      vars:          docroot:  /vagrant/www          servername:  mysite.dev      sudo:  yes      tasks:      -­‐  name:  ensure  nginx  is  at  the  latest  version          apt:  pkg=nginx  state=latest      -­‐  name:  write  the  nginx  config  file          template:  src=mysite.conf.j2  dest=/etc/nginx/sites-­‐ enabled/mysite.conf          notify:          -­‐  restart  nginx      -­‐  name:  ensure  nginx  is  running  (and  enable  it  at  boot)          service:  name=nginx  state=started  enabled=yes      handlers:          -­‐  name:  restart  nginx              service:  name=nginx  state=restarted

Slide 46

Slide 46 text

•First “vagrant up” •Vagrant provision

Slide 47

Slide 47 text

Organizing playbooks

Slide 48

Slide 48 text

-­‐group_vars      all.yml      webservers.yml      databases.yml   -­‐host_vars      webserver001.yml      webserver002.yml      database001.yml      database002.yml   -­‐playbook.yml   -­‐common.yml   -­‐roles      nginx      mysql Directory layout Variables per group or for all groups Variables per host Main playbook Included playbook Modularized playbooks

Slide 49

Slide 49 text

-­‐-­‐-­‐   -­‐  hosts:  webservers      pre_tasks:          -­‐  shell:  echo  'hello'      roles:          -­‐  nginx      tasks:          -­‐  shell:  echo  'still  busy'      post_tasks:          -­‐  shell:  echo  'goodbye' -­‐-­‐-­‐   -­‐  hosts:  databases      pre_tasks:          -­‐  shell:  echo  'hello'      roles:          -­‐  mysql      tasks:          -­‐  shell:  echo  'still  busy'      post_tasks:          -­‐  shell:  echo  'goodbye' -­‐-­‐-­‐   -­‐  hosts:  all      tasks:          -­‐  include:  common.yml          -­‐  shell:  echo  'still  busy'   -­‐-­‐-­‐   -­‐  hosts:  webserver001      tasks:          -­‐  shell:  echo  'very  busy'  

Slide 50

Slide 50 text

Inventory

Slide 51

Slide 51 text

Inventory $  cat  .vagrant/provisioners/ansible/ inventory/vagrant_ansible_inventory #  Generated  by  Vagrant   default  ansible_ssh_host=127.0.0.1   ansible_ssh_port=2202

Slide 52

Slide 52 text

Create custom inventory files for other environments

Slide 53

Slide 53 text

Re-use your Ansible scripts on test/staging/ production

Slide 54

Slide 54 text

Standalone Ansible

Slide 55

Slide 55 text

Standalone Ansible $  ansible-­‐playbook  -­‐i  inventory-­‐staging   playbook.yml

Slide 56

Slide 56 text

Multi-machine setup

Slide 57

Slide 57 text

Vagrant.configure(2)  do  |config|            config.vm.box  =  "ubuntu/trusty64"            config.vm.define  "webserver001",  primary:true  do  |ws001|              ws001.vm.hostname  =  "webserver001"              ws001.vm.network  :private_network,  ip:  "192.168.33.10"              ws001.vm.synced_folder  "./www",  "/var/www"                  end            config.vm.define  "webserver002"  do  |ws002|              ws002.vm.hostname  =  "webserver002"              ws002.vm.network  :private_network,  ip:  "192.168.33.11"              ws002.vm.synced_folder  "./www",  "/var/www"                  end                config.vm.define  "database001"  do  |db001|              db001.vm.hostname  =  "database001"              db001.vm.network  :private_network,  ip:  "192.168.33.12"      end            config.vm.define  "database002"  do  |db002|              db002.vm.hostname  =  "database002"              db002.vm.network  :private_network,  ip:  "192.168.33.13"      end            config.vm.provider  "virtualbox"  do  |vb|          vb.memory  =  "512"          vb.cpus  =  "2"        end      config.vm.provision  "ansible"  do  |ansible|                  ansible.playbook  =  "ansible/playbook.yml"                  ansible.groups  =  {                          "webservers"    =>  ["webserver001",  "webserver002"],                          "databases"      =>  ["database001",  "database002"],                                                  "all_groups:children"  =>  ["webservers",  "databases"]                  }      end   end

Slide 58

Slide 58 text

Inventory $  cat  .vagrant/provisioners/ansible/ inventory/vagrant_ansible_inventory #  Generated  by  Vagrant   database001  ansible_ssh_host=127.0.0.1  ansible_ssh_port=2204   database002  ansible_ssh_host=127.0.0.1  ansible_ssh_port=2205   webserver001  ansible_ssh_host=127.0.0.1  ansible_ssh_port=2202   webserver002  ansible_ssh_host=127.0.0.1  ansible_ssh_port=2203   [webservers]   webserver001   webserver002   [databases]   database001   database002   [all_groups:children]   webservers   databases

Slide 59

Slide 59 text

-­‐-­‐-­‐   -­‐  hosts:  webservers      pre_tasks:          -­‐  shell:  echo  'hello'      roles:          -­‐  nginx      tasks:          -­‐  shell:  echo  'still  busy'      post_tasks:          -­‐  shell:  echo  'goodbye' -­‐-­‐-­‐   -­‐  hosts:  databases      pre_tasks:          -­‐  shell:  echo  'hello'      roles:          -­‐  mysql      tasks:          -­‐  shell:  echo  'still  busy'      post_tasks:          -­‐  shell:  echo  'goodbye' -­‐-­‐-­‐   -­‐  hosts:  all      tasks:          -­‐  include:  common.yml          -­‐  shell:  echo  'still  busy'   -­‐-­‐-­‐   -­‐  hosts:  webserver001      tasks:          -­‐  shell:  echo  'very  busy'  

Slide 60

Slide 60 text

Controlling the machines

Slide 61

Slide 61 text

vagrant  up   vagrant  ssh   vagrant  destroy   vagrant  up  webserver001   vagrant  ssh  webserver001   vagrant  destroy  webserver001   vagrant  up  database001   vagrant  ssh  database001   vagrant  destroy  database001 All VM’s Primary VM All VM’s

Slide 62

Slide 62 text

Vagrant up #FTW

Slide 63

Slide 63 text

No content