I am new to chef-solo opscode and did not find out the way to the following
I am writing one template and passing data_bag json as variables to it
- recipe
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"] %>
- data bag
{
"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":{}
}
}
Its all working well, and what I want further is, while I execute it as below
sudo chef-solo -c solo.rb -j solo.json @development["password"]=my_new_passwd
@development["password"] should get overriden to my new value passed rather than from data bag
ANy hints?
Or any idea about merging two data bags?
Edited:
I want to add http://apidock.com/rails/Hash/deep_merge this to somewhere at chef init, so Hash class will have deep_merge method available, any idea where to put this? I tried at the top of recipe and solo.rb but no luck.
sudo chef-solo -c solo.rb -j solo.json @development["password"]=my_new_passwdwill not work because@developmentis a Ruby variable name not known on the command line - cmur2