- From: Jeppe Nejsum Madsen <
>
- To:
- Subject: [chef] Re: First-run Resources
- Date: Wed, 15 Jan 2014 11:50:07 +0100
<
>
writes:
>
Hi,
>
>
I'm creating a cookbook for deploying an application server (jruby & tomcat)
>
and database server (postgres).
>
>
There is a "rake db:setup" command that I need to run only once to set up
>
the
>
database structure. I wanted to do this with the "first run resource"
>
pattern
>
(http://docs.opscode.com/essentials_cookbook_resources_first_run.html) but
>
since the app server from which I run the rake command is a chef different
>
node
>
than the database server, it doesn't have permission to set an attribute on
>
it.
>
>
I'm able to manually give this permission from the hosted chef UI but I'm
>
looking at a way to grant this permission from my database server's recipe.
>
>
Any idea how I can do this? Or maybe a better way to store this flag? (Btw I
>
have one database server and possibly multiple app servers in each
>
environment).
I think a better approach is to check if the db:setup tasks needs to be
run on the box by check e.g. the database. We do something like this:
execute "add-#{database}-database" do
command %Q{
su - postgres -c "createdb -E=UTF8 --template=template0 -O
#{node[:postgresql][:dba_user]} #{database}"
}
not_if "su - postgres -c \"psql -c \\\"SELECT * FROM pg_database\\\"\" |
grep #{database}"
end
/Jeppe
Archive powered by MHonArc 2.6.16.