- RVM (or rbenv, but this will use RVM)
- You're using RVM or rbenv to manage your rubies, right? If not, you should be.
- Virtualbox
- some cookbooks you wrote and want to test
We don't want to mess up our carefully crafted Chef 10.x environment, right? We'll use rvm gemsets to make a disposable set of gems. If something goes wrong, just close the terminal you're in, or run rvm gemset use default
. You'll drop back to the default gemset.
cd $HOMEBASE
rvm gemset create chef11
rvm gemset use chef11
gem install chef vagrant
NOTE: update the homebase = to be the full path to your homebase.
cat <<VAGRANTFILE > Vagrantfile
homebase = "/path/to/homebase"
Vagrant::Config.run do |config|
config.vm.box = "opscode-ubuntu-12.04-chef11"
config.vm.box_url = "https://opscode-vm.s3.amazonaws.com/vagrant/opscode_ubuntu-12.04_chef-11.2.0.box" # from https://github.com/opscode/bento
config.vm.network :hostonly, "10.111.222.33"
config.vm.customize ["modifyvm", :id, "--memory", 2048]
config.vm.provision :chef_solo do |chef|
# chef.log_level = :debug
chef.cookbooks_path = "#{homebase}/cookbooks"
chef.data_bags_path = "#{homebase}/data_bags"
chef.roles_path = "#{homebase}/roles"
# Replace the following lines with your roles/recipes
chef.add_recipe "apt::default"
#chef.add_recipe "foo::bar"
# How to add a role:
# chef.add_role "foo"
# How to set node attributes (like an environment)
chef.json = {
:load_limit => 42,
:chunky_bacon => true
}
end
end
VAGRANTFILE
vagrant up
At this point, you should have an ubuntu 12.04 machine starting up, using Chef 11.2.0. It'll run the apt::default recipe (assuming you have it), and throw errors if there are any.
chef.add_recipe "foo::bar"
to add a recipechef.add_role "baz"
to add a role
If you're used to environments, you can run knife environment show <envname> --format json
to get an environment as json from your chef-server. You can also do knife node show <nodename> -a node -f j
to get all of the attributes from a particular node you already have. This gist can be adapted to get your json into the ruby 'hashrockets' syntax. Then you'll need to update the chef.json
in your Vagrantfile with your attributes.