Setting up a MySQL database with a user with Vagrant and chef-solo
Solution 1
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.
Solution 2
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
Related videos on Youtube
Thomas
Updated on June 15, 2022Comments
-
Thomas almost 2 years
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?
-
Thomas almost 12 yearsI already have a full chef-solo setup which installs tomcat, copies my war, installs MySQL etc. Currently, I have made a custom cookbook which just uses bash to create the database, but I'm hesitant to use bash for setting up a custom user etc. Here is the current recipe I've written for creating the database: bash "Attempting to create database 'foo'" do code <<-EOM mysql -uroot -e 'create database if not exists foo' EOM
-
Vishal Biyani almost 12 yearsYes, but if you download the recipes from Chef website, they will be ruby scripts. Or are you looking for something else?
-
Thomas almost 12 yearsI have all the recipes I need for setting up an image with MySQL and friends. My problem is configuring MySQL afterwards. I need to add a user and a database to the server. I know how to write my own recipe for doing this, hacking around in bash, but this does not seem to be an idiomatic way of doing this. I'm trying to figure out if the
database
recipe can be used for chef-solo for solving my use case. I'm afraid my original question wasn't clear enough. Does that make sense? -
Vishal Biyani almost 12 yearsNow got it absolutely! So creating a DB user in your MySQL DB is what you want to achieve? As long as your script is idempotent, they should be fine. I looked around a bit, and not sure what i found is what you need: gist.github.com/769365 but I would suggest writing a ruby or as a last resort shell script which is idempotent in creating the DB and users within it
-
Thomas almost 12 yearsYes! It was something like this I was looking for, although I hoped I would be able to use the
database
cookbook for it. This is a somewhat nice solution, although it would be even nicer if somebody pulled it put into a "proper" cookbook. Ah well, you can't have it all. -
Vishal Biyani almost 12 yearsMay be you can pull into a nice <code>cookbook</code> and commit to the repository, and become famous overnight (The last part is a joke :)