News for hackers. Stuff that matters.
Re:Vagrant 1.4 by AaronBBrown on Monday December 09, 2013 @08:22PM (#6878371)
I use Vagrant daily. Here's an example I was working on today.

I needed to spin up 5 servers, a load balancer and 2 groups of 2 backend servers. I needed to provision them with Chef, have full name resolution, and be able to access the servers from my host machine.

Here's my Vagrantfile

    Vagrant.require_plugin "vagrant-chef-zero"
    Vagrant.require_plugin "vagrant-berkshelf"
    Vagrant.require_plugin "landrush"

    last_ip_octet = 10
    DOMAIN = "vagrant.dev"

    Vagrant.configure("2") do |config|
      config.landrush.enable
      config.chef_zero.chef_repo_path = "./"
      config.omnibus.chef_version = '11.8.0'
      config.vm.box = "opscode_ubuntu-12.04_provisionerless"
      config.vm.box_url = "https://opscode-vm.s3.amazonaws.com/vagrant/opscode_ubuntu-12.04_provisionerless.box"

      %w{default metrics}.each do |backend|
        (1..2).each do |i|
          config.vm.define "be_#{backend}_#{i}".to_sym do |cfg|
            last_ip_octet += 1
            cfg.vm.hostname = "be-#{backend}-#{i}.#{DOMAIN}"
            cfg.vm.network :private_network, :ip => "192.168.33."+last_ip_octet.to_s
            cfg.vm.provision :chef_client do |chef|
              chef.node_name = "be-#{backend}-#{i}"
              chef.add_role "backend_#{backend}"
            end
          end
        end
      end

      config.vm.provision :shell, :inline => "/usr/bin/apt-get update --fix-missing"
      config.vm.define :lb do |cfg|
        last_ip_octet += 1
        lb_ip = "192.168.33."+last_ip_octet.to_s

        cfg.vm.hostname = "lb.#{DOMAIN}"
        cfg.vm.network :private_network, :ip => lb_ip
        cfg.vm.provision :chef_client do |chef|
          chef.node_name = "lb"
          chef.add_role "lb"
        end
      end
    end
This utilizes a few vagrant plugins, vagrant-chef-zero, vagrant-berkshelf, and landrush which are one liners each to install. After that, I can type

    vagrant up  # build my stack from scratch
    vagrant destroy # destroy my stack
    vagrant ssh lb # ssh into the lb instance
    vagrant provision # execute chef (puppet, ansible, bash, etc)
Can you show me equivalent code that fulfills all my requirements using VirtualBox directly and will allow me to change a couple lines to spin this same infrastructure up in AWS or using VMWare?

There are no comments on this comment yet.