- From: Klaas Jan Wierenga <
>
- To:
- Subject: [chef] Re: how best to create and fill a database in an idempotent fashion?
- Date: Thu, 1 Jul 2010 14:09:42 +0200
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=content-type:mime-version:subject:from:in-reply-to:date :content-transfer-encoding:message-id:references:to:x-mailer; b=cD11ZY2ZnUabOF1djbI1kJ1AI3D26NQt61mE8NftzRwIG0sJdt6AxaGMaoAyUH1yoL vWUW2g1u6Uj4ZVyNr+4zLOA9U3DXN88bqHl0baPCSyvWmQpG2DO1tqj/MMjv3nIH7Tar x5gDtmI+YvDJWJt4Mky4u+XDox89E30I6fil0=
Hi Dmitry,
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
Regards,
KJ
Op 1 jul 2010, om 12:19 heeft Dmitry V'yal het volgende geschreven:
>
Hello list,
>
>
I'm writing a receipt which creates a mysql database for my mail server.
>
I wrote a sql script and call it like this:
>
>
***
>
>
root_pass = node[:mysql][:server_root_password]
>
>
scheme_path = "/tmp/scheme.sql"
>
>
template scheme_path do
>
mode "600"
>
source "mysql-scheme.sql.erb"
>
end
>
>
execute "mysql-scheme" do
>
command "cat #{scheme_path} | mysql -u root -p#{root_pass}"
>
end
>
>
file scheme_path do
>
action :delete
>
end
>
>
***
>
>
Of course, this worked only the first time, the next chef run mysql
>
complained the database already exists.
>
>
How do you handle similar situations? What're the pros and cons of various
>
approaches?
>
>
Thanks,
>
Dmitry
Archive powered by MHonArc 2.6.16.