Skip to content

Latest commit

 

History

History
213 lines (154 loc) · 4.9 KB

File metadata and controls

213 lines (154 loc) · 4.9 KB
type slideOptions
slide
transition width height margin
slide
1400
900
0.1
<style> .reveal strong { font-weight: bold; color: orange; } .reveal p { text-align: left; } .reveal section h1 { color: orange; } .reveal section h2 { color: orange; } </style>

Vagrant


Introduction

  • Remember:

    If you can't git diff a file format, it's broken.

  • Infrastructure as code

    Vagrant is a tool for building and managing virtual machine environments in a single workflow.

    https://www.vagrantup.com/intro

  • Initial release 2010 by Mitchell Hashimoto, now HashiCorp

  • HashiCorp develops open-source DevOps/Cloud tools like Vagrant, TerraForm...


Building Blocks

  • Provisioners
    • Tool for configuring the boxes (install software on machine)
    • Examples: shell scripts, Chef, Puppet..
  • Providers
    • "Backend" on which the box is based
    • Examples: VirtualBox, Hyper-V, AWS, Docker...

What for?

  • Developing software
    • Set up consistent development environment
    • Share environment with others
  • Testing software, workflows...
    • Disposable environments
    • Consistent workflows
  • More general
    • Simple way to setup virtual machine
  • Reproducible environment

Advantages

  • Strong focus on workflow consistency
  • (Re)use existing images
  • Automatize VM creation and configuration
    • Easier than with VirtualBox CLI and shell scripts
  • Store in Git-friendly format
  • For us:
    • Management of VirtualBox VMs (testing, developing...)
    • Sharing of VMs (debugging, workshops...)

Some Useful Commands 1/2

  • vagrant init USERNAME/BOXNAME or URL
    • Initializes repository in current directory
    • Creates Vagrantfile -> Text file (Git friendly)
  • vagrant up
    • Create VM and start it
    • VM is stored in ${HOME}/.vagrant.d/boxes (overruled by VAGRANT_HOME)
  • vagrant ssh
    • Connect to VM via ssh
  • vagrant destroy
    • Stops the virtual machine and removes its disk

Some Useful Commands 2/2

  • vagrant box list
    • Show available boxes
  • vagrant box remove NAMEOFBOX
    • Remove a box completely
  • vagrant suspend
    • Suspends machine (sleep)
  • vagrant halt
    • Shuts down machine keeping changes
  • vagrant reload --provision or vagrant provision
    • Rebuild (partially) build image

Demo: Premade Vagrant VM

Details available in vagrant_demo.md


Structure of Vagrant Box

  • File Vagrantfile
    • Contains configuration of VM
    • Ruby script
  • Supplementary files, scripts etc. for configuring VM
    • Example: bootstrap.sh
  • Files are usually text files (Git friendly)

Setting up a Virtual Machine

  • Install VirtualBox

  • Install Vagrant (ideally from homepage so it is a recent release)

  • Create Vagrantfile and specify image

    Vagrant.configure("2") do |config|
        config.vm.box = "ajaust/sse-first-steps"
        config.vm.box_version = "0.1.0"
    end
  • Alternative:

    vagrant init ajaust/sse-first-steps
  • Start VM with vagrant up


Exchanging Files

  • Vagrant mounts shared folders

    • Check output when VM starts
    default: Mounting shared folders...
    • Files can be exchanged between Guest and Host (bidirectional)
  • Default:

    • Directory containing Vagrantfile mounted to /vagrant in Guest

Vagrant Cloud


Demo: Own box


Demo: preCICE VM


Summary

  • Open-source tool
  • Git-friendly way of configuring VMs
  • Simple management of VMs
  • Creates consistent workflows
  • Flexible due to big variety of provisioners and providers
  • Premade images can be used and shared

Further Reading