application_ruby database block and attributes

Hi,

How do I pass parameters (preferably via attributes) to the database block in the application_ruby cookbook?

What I want to do is something like:

application “my_app” do

rails do

database do
username node[:my_app][:db_user]
password node[:my_app][:db_password]
end
end
end

It looks like the database block does not have access to the node object.

I have the application resource inside a definition, so I also tried to pass parameters to it, like params[:db_user], but that does not work either.

How do I set those database parameters dynamically?

Cheers,
Cassiano Leal

On Jul 10, 2013, at 10:19 AM, Cassiano Leal wrote:

Hi,

How do I pass parameters (preferably via attributes) to the database block in the application_ruby cookbook?

What I want to do is something like:

application “my_app” do
...
rails do
...
database do
username node[:my_app][:db_user]
password node[:my_app][:db_password]
end
end
end

It looks like the database block does not have access to the node object.

I have the application resource inside a definition, so I also tried to pass parameters to it, like params[:db_user], but that does not work either.

How do I set those database parameters dynamically?

Its an issue with Ruby's method lookup order. Outside of that block (I usually just do it at the top of the file) do "blah = node[:my_app]" and then in the block you can do "username blah[:db_user]" and whatnot since then it knows that blah is a variable and not a method call :frowning: method_missing, got to love it!

--Noah

THANK YOU!

I tried that, and since it worked, I went inside my definition and did

parameters = params

and voilà! parameters[:db][:username] works just as well! :slight_smile:

  • cassiano

On Wednesday, July 10, 2013 at 14:25, Noah Kantrowitz wrote:

On Jul 10, 2013, at 10:19 AM, Cassiano Leal wrote:

Hi,

How do I pass parameters (preferably via attributes) to the database block in the application_ruby cookbook?

What I want to do is something like:

application “my_app” do
...
rails do
...
database do
username node[:my_app][:db_user]
password node[:my_app][:db_password]
end
end
end

It looks like the database block does not have access to the node object.

I have the application resource inside a definition, so I also tried to pass parameters to it, like params[:db_user], but that does not work either.

How do I set those database parameters dynamically?

Its an issue with Ruby's method lookup order. Outside of that block (I usually just do it at the top of the file) do "blah = node[:my_app]" and then in the block you can do "username blah[:db_user]" and whatnot since then it knows that blah is a variable and not a method call :frowning: method_missing, got to love it!

--Noah