- From: mayank verma <
>
- To:
- Subject: [chef] encrypted Databag values override
- Date: Thu, 20 Feb 2014 15:43:50 +0530
Hello, Stuck in databag values overriding.
case1: i have two data bags,
answer and
input.
answer databag contains default deployment configuration & input databag is containing user input. if input databag contains any key available in answer data bag overwrite the value of answer databag with input databag value.
i used deep merge concept to overwrite the data bag values that is working fine.
Compiling Cookbooks...
Code:
ans_config = data_bag_item("dbschema","oride")
override_config = data_bag_item("dbschema","merge")
puts "====INPUT===="
puts override_config["database"]
puts "=====ANSWER======"
puts ans_config["database"]
Chef::Mixin::DeepMerge.deep_merge! override_config["database"], ans_config["database"]
puts ans_config["database"]["name"]
puts ans_config["database"]["user"]
OutPut:
------
Compiling Cookbooks...
====INPUT====
{"name"=>"xyz"}
=====ANSWER======
{"user"=>"123", "name"=>"789"}
xyz
123
case2: same use case like case1, only difference is my
answer data bag is encrypted. Values of data bag is not overridden in encrypted data bag case.
Code:secret = Chef::EncryptedDataBagItem.load_secret("/home/pqrs/sample_key")
ans_config = Chef::EncryptedDataBagItem.load("dbschema", "oride", secret)
override_config = data_bag_item("dbschema","merge")
puts "====INPUT===="
puts override_config["database"]
puts "=====ANSWER======"
puts ans_config["database"]
Chef::Mixin::DeepMerge.deep_merge! override_config["database"], ans_config["database"]
puts ans_config["database"]["name"]
puts ans_config["database"]["user"]
OutPut:
Compiling Cookbooks...
====INPUT====
{"name"=>"xyz"}
=====ANSWER======
{"user"=>"123", "name"=>"789"}
789
123Expected OutPut for case2:
Compiling Cookbooks...
====INPUT====
{"name"=>"xyz"}
=====ANSWER======
{"user"=>"123", "name"=>"789"}
xyz
123
My Questions:
- why deep merge is not working in case of encrypted data bag if it is working in case of plain data bag.Even though in deep merge i am passing variables that holds hash values in both the cases.
- Any other alternate way to override databag values
Thanks in advance guys!
--
Thanks
Mayank
- [chef] encrypted Databag values override, mayank verma, 02/20/2014
Archive powered by MHonArc 2.6.16.