Wednesday, 20 May 2015

Vagrant quick tutorial

Vagrant

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 http://download.virtualbox.org/virtualbox/4.3.26/VirtualBox-4.3-4.3.26_98988_el6-1.x86_64.rpm
    rpm -Uvh VirtualBox*
  • create a vagrant file:
  • VAGRANTFILE_API_VERSION = "2"
     
    Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
     
      # Box
      config.vm.box = "ubuntu/precise64"
      config.vm.box_url = "http://cloud-images.ubuntu.com/vagrant/precise/current/precise-server-cloudimg-amd64-vagrant-disk1.box"
     
      # Shared folders
      config.vm.synced_folder ".", "/vagrant"
     
    end
  • 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 http://files.vagrantup.com/lucid32.box

No comments:

Post a Comment

connect ubuntu to wifi from command line

so i have a server install of a beta release of bionic beaver - ubuntu 18.04 - I want to connect this to wifi as I'm not near my cobble...