Wednesday, 20 May 2015

Vagrant quick tutorial


What is it?

Vagrant is a tool (front end) - uses a DSL (c.f. puppet also) - domain specific language - the purpose is to simplify the creation of virtual machines.
using DSL we get a repeatable formula for creating an end machine that will always be the same.

Why use it?

beneficial in a number of cases:
  • quick 'crash and burn' test sites
  • developers can get clean/consistent environments
  • can use to share a demo of an application or stack
I personally use it to test quite complex puppet stacks  - including apps. It gives me a  'clean' environment each time for testing - essentially create a new VM each time (takes a couple of minutes) - when finished testing I then destory the vm, freeing up resources.

What is it comprised of?

  • providers - this is the vagrant backend - I normally use virtualbox being from a linux shop, but could use vmware, aws etc
  • boxes - these are the predefined images to build env according to the DSL
  • vagrantfile - this contains the DSL and describes how the environment should be.
  • based on Ruby, unfortunately. ;-)

Enough already, I just want to do it.

  • yum install vagrant (I use rhel. sorry.) 
  • however its ruby - so can do gem install vagrant if so inclined
  • yum -y install VirtualBox
  • (if the yum install fails: wget
    rpm -Uvh VirtualBox*
  • create a vagrant file:
    Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
      # Box = "ubuntu/precise64"
      config.vm.box_url = ""
      # Shared folders
      config.vm.synced_folder ".", "/vagrant"
  • vagrant init (creates base config file)
  • vagrant up
  • vagrant ssh
  • vagrant halt
  • vagrant provision - runs provisioning commands
  • vagrant suspend (keeps state)
  • vagrant resume (starts where you left off)
  • vagrant reload (why not call this reboot?)
  • vagrant destroy
  • vagrant status
  • vagrant box list
  • vagrant package - creates new box files
  • can add a new box someone else has created:
  • vagrant box add lucid32

No comments:

Post a Comment

bash best practices

Bash best practices A few hints on bash best practice: * use #!/usr/bin/env bash .. this is more portable but you cant rely on a spe...