嵌套哈希未从属性传递到Chef配方

时间:2015-08-28 23:12:00

标签: ruby-on-rails ruby chef

我目前正在编写一个rails_web食谱,它已经为rails_web_app提供了定义。在食谱的默认配方中,我想迭代每个应用程序(键入对象的符号哈希):

default["rails_web"]["apps"] = [ { name: "my_app",
                             server_name: "localhost",
                             database_info: {
                                :host => "127.0.0.1",
                                :port => 5432,
                                :username => "postgres",
                                :password => "whocaresatm"
                               }
                           } ]

将app [" database_info"]传递给opscode的数据库cookbook的postgresql_database LWRP。

我认为这可以通过以下方式实现:

apps.each do |app|
  rails_web_app app["name"] do
    server_name app["server_name"]
  end
  postgresql_database app["name"] do
    connection app["database_info"]
    action :create
  end
end

因为我的rails_web_app定义已经通过从上面的哈希中提取信息而工作,并且数据库菜谱作者展示了:

postgresql_connection_info = {
  :host     => '127.0.0.1',
  :port     => node['postgresql']['config']['port'],
  :username => 'postgres',
  :password => node['postgresql']['password']['postgres']
}

postgresql_database 'foo' do
  connection postgresql_connection_info
  action     :create
end

但是,当我尝试运行默认配方(食谱编译工作正常)时,我得到了

Chef::Exceptions::ValidationFailed
10.5.32.101   ----------------------------------
10.5.32.101   Required argument connection is missing!
10.5.32.101   
10.5.32.101   Cookbook Trace:
10.5.32.101   ---------------
10.5.32.101     /var/chef/cache/cookbooks/database/libraries/resource_database.rb:41:in `connection'
10.5.32.101     /var/chef/cache/cookbooks/rails_web/recipes/default.rb:43:in `block (2 levels) in from_file'
10.5.32.101     /var/chef/cache/cookbooks/rails_web/recipes/default.rb:41:in `block in from_file'
10.5.32.101     /var/chef/cache/cookbooks/rails_web/recipes/default.rb:37:in `each'
10.5.32.101     /var/chef/cache/cookbooks/rails_web/recipes/default.rb:37:in `from_file'
10.5.32.101   
10.5.32.101   Relevant File Content:
10.5.32.101   ----------------------
10.5.32.101   /var/chef/cache/cookbooks/database/libraries/resource_database.rb:
10.5.32.101   
10.5.32.101    34:            :database_name,
10.5.32.101    35:            arg,
10.5.32.101    36:            kind_of: String
10.5.32.101    37:          )
10.5.32.101    38:        end
10.5.32.101    39:  
10.5.32.101    40:        def connection(arg = nil)
10.5.32.101    41>>         set_or_return(
10.5.32.101    42:            :connection,
10.5.32.101    43:            arg,
10.5.32.101    44:            required: true
10.5.32.101    45:          )
10.5.32.101    46:        end
10.5.32.101    47:  
10.5.32.101    48:        def sql(arg = nil, &block)
10.5.32.101    49:          arg ||= block
10.5.32.101    50:          set_or_return(

我在这里缺少什么?显然nil正在传入,但我不太了解rails_web_app定义如何完美地从apps []属性中获取字符串,而postgresql_database LWRP无法处理符号散列作为映射到其他的键东西。我的语法有点不对,但调整了一段时间并没有让我到处找。

0 个答案:

没有答案