Veewee for Ruby Rubes

Tags: devops

Let’s talk about installing Veewee to build virtual machines on multiple platforms from templates with little to no ruby background. Ruby professionals will probably do just fine with the install instructions provided by the project. Stick around if you’re a system administrator, operations engineer, or non-ruby developer interested in installing veewee.

We’re going to follow along with veewee’s installation instructions, but I’m also going to provide some commentary and direction as I received it from someone who writes software with ruby on a daily basis.

After installing required operating system packages we come to the first fork in the road. Two options with a silent third option exist for managing our Ruby environment:

  1. RVM (preferred by Veewee)
  2. rbenv (preferred by Joe)
  3. No environment management (preferred by no one sane)

Number three is an option in the technical sense only. Don’t think it’s a wise idea to stink up the system Ruby installation with custom gems. You’re entering a world of pain.

RVM felt a little weird to me, but I chalked that up to being a Ruby rube. Joe told me that he dropped RVM years ago for rbenv and hasn’t looked back. Those two factors pushed me to switch to rbenv, but your mileage may vary. For the python folks in the room, you can equate (RVM || rbenv) + Bundler to virtualenv + pip.

I followed the rest of the installation, command options, and basics pages. Everything worked, and I created several virtual machines using the KVM plugin, but it didn’t quite feel right. I didn’t see anywhere in the docs an explanation of how to separate my work from their work.
Templates and definitions lived inside of the veewee source directory, and “bundle exec veewee” only worked within that directory.

Aside from the ugliness of polluting a directory full of upstream source with my own stuff that I never intended to contribute back, I really wanted a nice way to manage separate repositories of templates and definitions for my personal use and work use.

I saw reference to Veeweefiles in the docs, but not much information on how to use them to customize runtime configuration. Digging in to the code, environment.rb specifically, there was a reference to a VEEWEE_DIR environment variable. Setting that allowed me to run bundle exec veewee from the veewee source directory, but use templates, definitions, and isos in a separate directory. Excited about this new development, I shared the news with some folks in IRC.

Joe again stepped in to let me know that I was just barely catching up to the crowd, and not even in a very ideal way.

make a gemfile that includes veewee, run bundle it, then the above command [works in your personal directory for templates and definitions]”

I ended up with a directory structure like so:

tim@gauss:~/src/veewee-freund$ pwd
/home/tim/src/veewee-freund
tim@gauss:~/src/veewee-freund$ find .
.
./definitions
./definitions/custom-ubuntu-definition
./definitions/custom-ubuntu-definition/base.sh
./definitions/custom-ubuntu-definition/chef.sh
./definitions/custom-ubuntu-definition/cleanup.sh
./definitions/custom-ubuntu-definition/definition.rb
./definitions/custom-ubuntu-definition/preseed.cfg
./definitions/custom-ubuntu-definition/puppet.sh
./definitions/custom-ubuntu-definition/ruby.sh
./definitions/custom-ubuntu-definition/vagrant.sh
./definitions/custom-ubuntu-definition/virtualbox.sh
./definitions/custom-ubuntu-definition/vmfusion.sh
./definitions/custom-ubuntu-definition/vmtools.sh
./definitions/custom-ubuntu-definition/zerodisk.sh
./Gemfile
./Gemfile.lock
./iso
./templates
./templates/ubuntu-12.04.2-server-amd64
./Veeweefile

Bash

With a very short Gemfile:

source "http://rubygems.org"
 
gem "veewee"
gem "ruby-libvirt"

Ruby

And a minimal Veeweefile

Veewee::Config.run do |config|
 
# Initialize convenience vars
cwd = File.dirname(__FILE__)
env = config.veewee.env
 
# These env settings will override default settings
#env.cwd = cwd
#env.definition_dir = File.join(cwd, 'definitions')
env.template_path = [File.join(cwd, 'templates')]
#env.iso_dir = File.join(cwd, 'iso')
#env.validation_dir = File.join(cwd, 'validation')
#env.tmp_dir = "/tmp"
 
end

Ruby

And it seems to all work. Just to be clear:

  1. Create a new directory for your veewee work.
  2. Drop the Gemfile and Veeweefile above in the directory.
  3. Run bundle install
  4. Optionally alias veewee=”bundle exec veewee”
  5. Create templates and define boxes to your heart’s content.