Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting up a MySQL database with a user with Vagrant and chef-solo

I'm trying to automate the developer setup on a project, such that a new developer can simply issue vagrant up to get a VM with MySQL and Tomcat with a custom war-file deployed up and running. The deployed-war assumes that a particular database and user are present on the MySQL instance.

Now, I'm using chef-solo, and everything is booting up and installing correctly. However, I can't seem to figure out how to write a cookbook for setting up the database and the user. I've looked into the database cookbook, but that does not seem to fit my use case with chef-solo. I've been unable to find an example setup online that sets up a database for a chef-solo instance, but maybe I'm searching for the wrong terms?

I could write a bash script for setting up the database and user (conditional on them not existing), but that does not seem to fit into the cookbook philosophy. How would you solve this problem?

like image 889
Thomas Avatar asked Jun 21 '12 07:06

Thomas


2 Answers

Yeah you can do it the Chef way just like this with the database cookbook:

include_recipe "database::mysql"

# create a mysql database
mysql_database 'sonar' do
  connection ({:host => "localhost", :username => 'root', :password => node['mysql']['server_root_password']})
  action :create
end

more about this cookbook can be found here: http://community.opscode.com/cookbooks/database

like image 133
Matthias B Avatar answered Nov 19 '22 05:11

Matthias B


For Chef solo you will need to do some configurations have you done it? Configurations I am talking about are here The same page also provides a quick small demo of how to configure and run a cookbook, after which you can:

Cookbook for MySQL is here Cookbook for Tomcat is here

Other cookbooks can be found here

That's closest I can get to based on data you have provided. Once you have configured this and setup stuff, if you face errors, post them. And hopefully I was helpful :)

I would configure the Chef Solo first and then place Cookbooks in one of configured directories.

like image 42
Vishal Biyani Avatar answered Nov 19 '22 03:11

Vishal Biyani