Skip to content

Instantly share code, notes, and snippets.

@iturgeon
Created November 29, 2012 19:45
Show Gist options
  • Save iturgeon/4171379 to your computer and use it in GitHub Desktop.
Save iturgeon/4171379 to your computer and use it in GitHub Desktop.
Chef and Vagrant setup to easily create databases as needed
# create all the databases from the Vagrantfile json config
node[:db].each do |env, name|
execute "create database #{name}" do
command "mysql -uroot -p#{node[:mysql][:server_root_password]} -e 'create database if not exists #{name}'"
user "vagrant"
end
end
Vagrant::Config.run do |config|
config.vm.box = "lucid32"
config.vm.box_url = "http://files.vagrantup.com/lucid32.box"
config.vm.provision :chef_solo do |chef|
chef.cookbooks_path = "cookbooks"
# pass json_attribs to chef
chef.json = {
"development" => true,
"mysql" => {
"server_root_password" => "<PW>",
"allow_remote_root" => true,
"bind_address" => "0.0.0.0",
},
"db" => {
"prod" => "db_prod",
"test" => "db_test",
"dev" => "db_dev"
}
}
end
@daviddarke
Copy link

Just what I needed! cheers!

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