Friday, May 16, 2014

Provisioning Vagrant with Chef-Zero on Ubuntu 14.04 Trusty

I'm building a Vagrant instance for development and I want to use Chef to provision the machine.

I'm on Ubuntu Trusty 64. Running with the packaged versions of Vagrant and Ruby is a fool's errand. I used the Vagrant 1.5.4 package. Vagrant has an embedded Ruby which causes all kinds of grief cross-linking with stuff in the Ubuntu versions of the packages. I ended up removing them wholesale, but you may be ok if you be sure and always use the binaries from: /opt/vagrant/embedded/bin/

It took me almost a week to figure this out thanks to a lot of very unhelpful errors and red herrings. I figured I'd do a write-up and save you some suffering.
# Add the base vagrant box
vagrant box add ubuntu/trusty64 http://cloud-images.ubuntu.com/vagrant/trusty/current/trusty-server-cloudimg-amd64-vagrant-disk1.box

# Setup the vagrant instance
cd my-project
vagrant init ubuntu/trusty64

# Setup berkshelf and fix some path grief
env SSL_CERT_FILE=/opt/vagrant/embedded/cacert.pem /opt/vagrant/embedded/bin/berks
rm -rf ~/.berkshelf/default/cookbooks/
ln -s ~/.berkshelf/cookbooks/ ~/.berkshelf/default/cookbooks

# Get dependencies
sudo /opt/vagrant/embedded/bin/gem install bundler
/opt/vagrant/embedded/bin/bundle
vagrant plugin install vagrant-chef-zero
vagrant plugin install vagrant-berkshelf --plugin-version '>= 2.0.0'
Update your Vagrantfile:
config.berkshelf.enabled = true
config.chef_zero.enabled = true
config.chef_zero.environments = "./environments/"
config.chef_zero.data_bags = "./data_bags/"
config.chef_zero.roles = "./roles/"
config.chef_zero.cookbooks = "./cookbooks/"

config.vm.provision :chef_client do |chef|
  chef.run_list = [
    "role[base]" # Yours may be different
  ]
end
Then:
vagrant up

2 comments:

Pak said...

How do you install Berkshelf on Ubuntu 14.04 ? the advised method is with Chef DK but the package does not seem to be suitable for 14.04. Thanks !

Jeff Rodriguez said...

It's been a while now so I'm not entirely sure anymore.

Try using the embedded gem command for your gem install berkshelf

Good luck! If you figure it out, please post an update here for anyone else who needs it :)