[chef] Re: Re: how best to create and fill a database in an idempotent fashion?


Chronological Thread 
  • From: Joshua Timberman < >
  • To:
  • Subject: [chef] Re: Re: how best to create and fill a database in an idempotent fashion?
  • Date: Thu, 1 Jul 2010 10:23:21 -0600

Hello!


On Jul 1, 2010, at 6:09 AM, Klaas Jan Wierenga wrote:

> This snippet from cookbooks/wordpress/recipes/default.rb might give you an 
> idea. Look at the not_if clause.
> 
> execute "create #{node[:wordpress][:db][:database]} database" do
>  command "/usr/bin/mysqladmin -u root 
> -p#{node[:mysql][:server_root_password]} create 
> #{node[:wordpress][:db][:database]}"
>  not_if do
>    m = Mysql.new("localhost", "root", node[:mysql][:server_root_password])
>    m.list_dbs.include?(node[:wordpress][:db][:database])
>  end
> end


Also note that this uses the mysql rubygem which needs to be installed 
earlier in the Chef run by using the compile-time resource creation. The 
mysql::server recipe used in the wordpress cookbook does this when it 
includes the mysql::client recipe:

mysql::client - 

r = gem_package "mysql" do
  action :nothing
end
                           
r.run_action(:install)

wordpress - 

include_recipe "mysql::server"
require 'rubygems'
Gem.clear_paths
require 'mysql'

The Gem.clear_paths is significant, so the load path is set up correctly to 
find the newly installed mysql gem. Your node will also need to be able to 
compile rubygem native extensions to install the mysql gem.

-- 
Opscode, Inc
Joshua Timberman, Senior Solutions Engineer
C: 720.334.RUBY E: 





Archive powered by MHonArc 2.6.16.

§