INtroduction

To 

Vagrant

Daniel Farrell
Red Hat
SDN Team, R&D Office
@dfarrell07

WHAT'S VAGRANT?

VAGRANT

A tool for working with Virtual Machines

Vagrant

A modular framework for working with VMs

VAGRANT

All through a Vagrantfile
$ cat Vagrantfile
Vagrant.configure(2) do |config|
  config.vm.box = "centos/7"
end

VAGRANT

Simple commands
$ vagrant up
$ vagrant ssh
[vagrant@localhost ~]$

That's Cool, But...

THAT'S COOL, BUT...

$ VBoxManage createvm <many flags>

"Write a shell script that does the following..."

Vagrant

Vagrant

[vagrant@localhost ~]$ ping 8.8.8.8
64 bytes from 8.8.8.8: icmp_seq=1 ttl=63 time=36.4 ms

Vagrant

[vagrant@localhost ~]$ ls /vagrant/
Vagrantfile
[vagrant@localhost ~]$ touch /vagrant/foo
[vagrant@localhost ~]$ logout
$ ls
foo  Vagrantfile

VAGRANT

Modular VM deploy/config

*important concept*

*IMPORTANT CONCEPT*

Providers and Provisioners

Providers

PROVIDERS

"Provide" virtualization support 

PROVIDERS

Magic VMs into existence

PROVIDERS

Local or remote

PROVIDERS

Local
(VirtualBox, libvirt, VMWare, Docker...)

PROVIDERS

Remote
(OpenStack, Digital Ocean, AWS...)

Provisioners

PROVISIONERS

"Provision" the VM

PROVISIONERS

Shared, repeatable config

PROVISIONERS

Simple on-ramp
(Shell)

PROVISIONERS

Powerful options
(Ansible, Puppet, Chef, Salt...)


Mix and match providers and provisioners

Example: Minimal

EXAMPLE: MINIMAL

$ vagrant init -m centos/7
$ cat Vagrantfile
Vagrant.configure(2) do |config|
  config.vm.box = "centos/7"
end

EXAMPLE: MINIMAL

$ vagrant up
# Base box downloads if not cached
# VM boots
# Cross-OS networking magic
# Cross-OS shared dir magic

EXAMPLE: MINIMAL

$ vagrant ssh
[vagrant@localhost ~]$

Example: Shell

EXAMPLE: SHELL

Vagrant.configure(2) do |config|
  config.vm.box = "boxcutter/fedora22"
  config.vm.provision "shell", inline: "dnf install -y <system deps>"
end

EXAMPLE: Shell

$ vagrant up
# (networking, mount and other magic)
# Shell provisioner runs, <system deps> are installed

Example: AnSible

EXAMPLE: ANSIBLE

Vagrant.configure(2) do |config|
  config.vm.box = "boxcutter/fedora22"

  config.vm.provision "ansible" do |ansible|
    ansible.playbook = "provisioning/playbook.yml"
  end
end

Example: Ansible

ansible.playbook = "provisioning/playbook.yml"

EXAMPLE: Ansible

[~/vagrant-opendaylight]$ cat provisioning/playbook.yml
---
- hosts: all
  sudo: yes
  roles:
    - opendaylight

EXAMPLE: Ansible

$ vagrant up
# (networking, mount and other magic)
# Ansible provisioner runs, OpenDaylight is installed

EXAMPLE: ANSIBLE

$ vagrant ssh
[vagrant@localhost ~]$ sudo systemctl is-active opendaylight
active

Why VAgrant?

WHY VAGRANT?

Well-defined environments

WHY VAGRANT?

Environment shared by all devs

WHY VAGRANT?

Vagrantfile history in version control

WHY VAGRANT?

Vagrantfiles replace binary VM blobs

WHY VAGRANT?

Environment ships with the code

WHY VAGRANT?

Reuse existing config management logic

WHY VAGRANT?

Remote deploys ~= Local deploys

Contact

Daniel Farrell
Twitter (optimal):

Others:
dfarrell@redhat.com
dfarrell07 on IRC, GitHub

Lightning Talk: Intro to Vagrant

By Daniel Farrell

Lightning Talk: Intro to Vagrant

Introduction to Vagrant lightning talk for All Things Open 2015.

  • 2,336