Skip to content

Instantly share code, notes, and snippets.

@fnichol
Created January 3, 2011 16:20
Show Gist options
  • Save fnichol/763629 to your computer and use it in GitHub Desktop.
Save fnichol/763629 to your computer and use it in GitHub Desktop.
Sample chef-solo config for vagrant prototyping

Setting Up Vagrant With Ubuntu 10.10 (32-bit)

Setup

First you need to ensure that VirtualBox is installed. Current vagrant release is not working with VirtualBox 4.x, so get a previous 3.2.x version (currently 3.2.10 which updates to 3.2.12) from http://www.virtualbox.org/wiki/Download_Old_Builds_3_2.

Next install the vagrant gem and download the Ubuntu 10.10 32-bit vagrant box I built up:

gem install vagrant
vagrant box add maverick32 http://dl.dropbox.com/u/2297268/maverick32.box

The box is about 500MB to download and gets cloned off your local disk whenever vagrant builds a virtual machine.

Creating A Vagrant VM

Now make a directory for a vagrant virtual machine "project":

mkdir webapp_testing
cd webapp_testing

To save some time and to see an example, you can start from the Vagrantfile in this gist:

curl  -LO https://gist.github.com/raw/763629/998aa2af2b69e363f9109b000de7a0ba01b04e63/Vagrantfile 

Note that these roles and recipes are partially using my chef repo:

git clone git://github.com/fnichol/chef-repo.git

I'm using some git submodules to split the base repo from the opscode cookbooks fork from my own totally new cookbooks. On your workstation make sure that the chef gem is installed for the rake task to work:

gem install chef
(cd chef-repo && rake update)

Managing The Vagrant VM

Then you can try to bring up the virtual machine. I'm always interesting in deployment time:

time vagrant up

To see much more chef deployment information, turn on debug level logging in the Vagrantfile (currently commented out).

Assuming that you don't make a new chef cookbook or add any port forwards, you can re-run chef-solo from vagrant like so (without a VM restart):

vagrant provision

To change any VirtualBox VM settings or add any new cookbooks/recipes you'll need to tell vagrant to fully restart/reprovision the VM:

vagrant reload

To log in to your VM, use the following (from your testing_webapp directory with the Vagrantfile):

vagrant ssh

If you want to keep your work around when you're done, ssh in to your VM and shut it down:

vagrant ssh
sudo shutdown -hP now && exit

If you want to destroy the VM and reclaim space, then destroy it:

vagrant destroy

Resources

##
# Source from: https://gist.github.com/763629
#
# A demo/work-in-progress configuration for a db/web server node roughly running:
# - mysql server
# - rvm
# - ree-1.8.7 (via rvm)
# - nginx-0.8.x/passenger-3.0.x
# - deployment stubs for a rails webapp called `rails_webapp' with a `deploy' user
# ready for capistrano-style deployment
#
# Note that the mysql server root password is currently hardcoded because of a
# shortcoming in chef-solo not keeping track of random password state between
# provision runs. Kinda stupid, but that stalled me for 4 days ;) Also, the
# `users/deploy'deploy_keys' attribute isn't filled out--put your ssh pub keys from
# where you `cap deploy'.
#
Vagrant::Config.run do |config|
config.vm.box = "maverick32"
config.vm.forward_port "http", 80, 8080
config.vm.provisioner = :chef_solo
config.chef.cookbooks_path = "chef-repo/cookbooks"
config.chef.roles_path = "chef-repo/roles"
#config.chef.log_level = :debug
config.chef.add_recipe "vagrant_extras"
config.chef.add_role "mysql_server"
config.chef.add_role "web_server"
config.chef.add_recipe "webapp"
config.chef.json.merge!({
:rvm => {
:rvmrc => {
:rvm_gemset_create_on_use_flag => 1,
:rvm_trust_rvmrcs_flag => 1
}
},
:mysql => {
:server_root_password => "mysqlpasswd"
},
:webapp => {
:apps => [
{ :id => "rails_webapp",
:profile => "rails",
:host_name => "0.0.0.0"
}
],
:users => {
:deploy => {
:deploy_keys => [
"ssh-dss MYLONGSSHPUBKEY..."
]
}
}
}
})
end
@paulodeon
Copy link

Kinda stupid, but that stalled me for 4 days ;)
Thanks for this, It stalled me for ages as well, thanks for all your cookbooks as well, really useful!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment