1

我是 chef-solo opscode 的新手,没有找到以下方法

我正在编写一个模板并将 data_bag json 作为变量传递给它

- 食谱

HOME = ""

app_config = data_bag_item("config","app")

template "#{HOME}/app/config/database.yml" do
  local true
  source "#{HOME}/app/config/database.yml.erb"
  variables app_config["database.yml"]
endt

-erb

development:
  adapter: <%= @development["adapter"] %>
  database: <%= @development["database"] %>
  username: <%= @development["username"] %>
  password: <%= @development["password"] %>
  encoding: <%= @development["encoding"] %>
  host: <%= @development["host"] %>

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
  adapter: <%= @test["adapter"] %>
  database: <%= @test["database"] %>
  username: <%= @test["username"] %>
  password: <%= @test["password"] %>
  encoding: <%= @test["encoding"] %>
  host: <%= @test["host"] %>

production:
  adapter: <%= @production["adapter"] %>
  database: <%= @production["database"] %>
  username: <%= @production["username"] %>
  password: <%= @production["password"] %>
  encoding: <%= @production["encoding"] %>
  host: <%= @production["host"] %>

- 数据包

{
  "id" : "app",

   "database.yml" : {
    "development": {
      "adapter"   : "mysql2",
      "database"  : "app_site",
      "username"  : "root",
      "password"  : "",
      "encoding"  : "utf8",
      "host"      : "localhost"
    } ,
    "production" : {
      "adapter"   : "mysql2",
      "database"  : "app_site",
      "username"  : "root",
      "password"  : "",
      "encoding"  : "utf8",
      "host"      : "localhost"
    } ,
    "test": {
      "adapter"   : "mysql2",
      "database"  : "app_site_test",
      "username"  : "root",
      "password"  : "",
      "encoding"  : "utf8",
      "host"      : "localhost"
    }
  },

  "config.yml":{
     "development":{},
     "production" :{},
     "test":{}
  }
}

它一切正常,我想要进一步的是,当我执行它时,如下所示

sudo chef-solo -c solo.rb -j solo.json @development["password"]=my_new_passwd

@development["password"]应该被覆盖为我传递的新值,而不是来自数据包

任何提示?

或者关于合并两个数据包的任何想法?

编辑:

我想将http://apidock.com/rails/Hash/deep_merge添加到 Chef init 的某个地方,因此 Hash 类将提供 deep_merge 方法,知道该放在哪里吗?我尝试在recipe 和solo.rb 的顶部,但没有运气。

4

1 回答 1

1

https://github.com/sensu/sensu-chef/pull/14#issuecomment-16521845

HOME = "#{ENV['HOME']}"

app_config = data_bag_item("config","app")
override_config = data_bag_item("config","override")

# merging override into app
Chef::Mixin::DeepMerge.deep_merge! override_config["database.yml"], app_config["database.yml"]

template "#{HOME}/app/config/database.yml" do
  local true
  source "#{HOME}/app/config/database.yml.erb"
  variables app_config["database.yml"]
end
于 2013-04-18T09:19:14.697 回答