[chef] Re: Re: Are all attribute files included even when their corresponding recipes are not?


Chronological Thread 
  • From: Jay Buffington < >
  • To:
  • Subject: [chef] Re: Re: Are all attribute files included even when their corresponding recipes are not?
  • Date: Wed, 27 Apr 2011 10:49:23 -0700
  • Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:content-type :content-transfer-encoding; b=M8cmUWDMijaQigjM/eKSVQQKwQhsF9ugXHqdJYD8XRB/1J8wC0yVySgS1M36XR/gW7 TMCZSa6n5u7mXAMp/xMvnxPDOb4U0T1wt3RVWXWCfZRFM7XcwImLBi5CLzTOn9xaBMA/ XA474fMmXBUPnFK1wBcRxLmOjo058CbTfHo9s=

> That is precisely where they should be set :). Hence this ticket:
>
> http://tickets.opscode.com/browse/COOK-526
>
> To further explain the reason why they should be in the recipe isn't just 
> because they're only used by that recipe, but also because they are 
> calculated. The attributes files are really meant to be as declarative as 
> possible to set sane defaults for the cookbook so using the attributes can 
> be done without causing some nil error on attributes that don't exist.

That makes a lot of sense.  For now I've worked around it by putting
this in my recipe:

begin
    dbh = ::Mysql.connect(node[:app][:database][:host],
node[:app][:database][:user], node[:app][:database][:password])
    dbh.select_db( node[:app][:database][:name] )
rescue
    log "looks like the #{node[:app][:database][:name]} database
doesn't exist, creating it and granting permissions to
#{node[:app][:database][:user]}"

    # if the above throws, we need to provision the database
    mysql_database "create #{node[:app][:database][:name]} database" do
        host node[:app][:database][:host]
        username "root"
        password node[:mysql][:server_root_password]
        database node[:app][:database][:name]

        sql "GRANT ALL ON #{node[:app][:database][:name]}.* TO
'#{node[:app][:database][:user]}'@'#{node[:app][:database][:host]}'
IDENTIFIED BY '#{node[:app][:database][:password]}'"

        action [:create_db, :query]
    end
ensure
    dbh.close if dbh
end

I removed the info line in the mysql lwrp that logs the query that is
being executed so my password doesn't show up in the logs.

Jay



Archive powered by MHonArc 2.6.16.

§