【发布时间】:2013-04-17 13:42:06
【问题描述】:
我是 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 的顶部,但没有运气。
【问题讨论】:
-
sudo chef-solo -c solo.rb -j solo.json @development["password"]=my_new_passwd将不起作用,因为@development是命令行上未知的 Ruby 变量名称 -
我知道,我想做一些类似的工作
-
问题是你的solo.json 已经是最重要的,最“临时”的方式来传递个人数据给厨师,所以试图覆盖它会很困难。也许您可以尝试将数据放在节点属性而不是 data_bags 中,因为前者更容易覆盖:您将 app_config 放置在分配给节点的角色中,然后通过 solo.json 中给出的节点属性覆盖一些设置。
-
那太好了@cmur2,任何例子都会有很大帮助。
标签: automation chef-infra chef-recipe chef-solo