Home > cloud, ruby, web > Quick way to bootstrap chef server with vagrant

Quick way to bootstrap chef server with vagrant

August 26th, 2010 alex Leave a comment Go to comments

As a big fan of automatic software deployment and cloud computing, today I tried chef following several tutorials one, two and three. But because I am lazy, I decided to try to use vagrant to setup chef server.

Vagrant is a absolutely amazing wrapper for Virtual Box and can provision virtual machines on a spot using chef-solo or chef-server. I have a lot of plans for vagrant+chef. Lets start: * Download and install Oracle Virtual Box, OSE version would not work * install ruby and rubygems. Mine ruby 1.8.7 (2010-08-16 patchlevel 302) [i686-darwin10.4.0]), with gems 1.3.6 via rvm. I highly recommend using rvm, as I had to drop 1.3.7 rubygems due to incompatibility with chef’s cookbooks. ( Possibly, now sorted)

  1. gem install vagrant
  1. mkdir -p /ruby/Vagrant
  2. cd ~/ruby/Vagrant

Following quickstart:

  1. vagrant box add lucid32 http://files.vagrantup.com/lucid32.box
  2. vagrant init
  3. vagrant up

, so my base box is lucid32

At this stage you should have virtual box and vagrant fully functional. Now

  1. git clone http://github.com/thewoolleyman/cookbooks.git other_cookbooks

I tried to use official opscode cookbooks, but they currently have mysql cookbook broken, which breaks wordpress cookbook and others I wanted to play with. Now add to Vagrantfile:

config.vm.define :chefs do |chefs_config|
chefs_config.vm.box = "base"
chefs_config.vm.provisioner = :chef_solo
chefs_config.chef.cookbooks_path = "other_cookbooks"
chefs_config.chef.run_list.clear
chefs_config.chef.add_recipe("apt")
chefs_config.chef.add_recipe("build-essential")
chefs_config.chef.add_recipe("chef::bootstrap_server")
chefs_config.vm.forward_port("chefs", 4000, 4000)
chefs_config.vm.forward_port("ssh", 22, 2223,:auto => true)
chefs_config.chef.json={
:chef=> {
:server_url=> "http://localhost.localdomain:4000",
:webui_enabled=> true,
}
}
end
Obviosly it should be between Vagrant::Config.run do |config| and end. now

vagrant up chefs
  1.  should start and provision chef server.
  2. logging into it using vagrant ssh chefs should allow to continue first tutorial from <pre lang="shell">"e) #knife configure -i"

Alternative way to use chef server without installing your own is to subscribe to opscode platform. Vagrant configuration for this, using wordpress chef cookbook:

  1. config.vm.define :web do |web_config|
  2. web_config.vm.box = "base"
  3. # config.vm.provisioner = :chef_solo
  4. web_config.vm.provisioner = :chef_server
  5. web_config.chef.chef_server_url = "https://api.opscode.com/organizations/ORGANIZATION"
  6. web_config.chef.validation_client_name = "ORGANIZATION-validator"
  7. web_config.chef.validation_key_path = "/Users/*/Dropbox/chef_opscode/client-config/validation.pem"
  8. web_config.chef.run_list.clear
  9. web_config.chef.add_recipe("wordpress")
  10. web_config.vm.forward_port("web", 80, 8080)
  11. web_config.vm.forward_port("ssh", 22, 2222,:auto => true)
  12. end

Which is now gives virtual machine with wordpress install

vagrant up web
Stay tuned for more articles featuring Dropbox, vagrant, virtual box and possibly Pareto. Update: There is a newer version of the post

Tags: , , , , ,