I see. So Dorian’s problem would probably be best solved by using
node.normal[:myapp][:part1][:conf] = “XXX1” unless node[:myapp][:part1][:conf]
Right?
On July 23, 2013 at 09:56:38, Sean OMeara ( " target="_blank"> ) wrote:
chef-shell will free your mind...$ chef-shell -schef > recipe_modechef:recipe > node.default['noxexistent'].class=> Chef::Node::VividMashWhen you access an attribute that does not exist from a recipe, it returns as an empty Chef::Node::VividMash object, not nil.This is why your 'or' statement is failing =)Some other trivia: 'node.set' is the same as 'node.normal'.chef:recipe > node.default['foo'] = "bar"=> "bar"chef:recipe > node['foo']=> "bar"chef:recipe > node.normal['foo'] = "baz"=> "baz"chef:recipe > node['foo']=> "baz"chef:recipe > node.override['foo'] = "biz"=> "biz"chef:recipe > node['foo']=> "biz"Yet, all three are actually persisted on the node objectchef:recipe > node.default['foo']=> "bar"chef:recipe > node.normal['foo']=> "baz"chef:recipe > node.override['foo']=> "biz"The chef-client only consumes the one with the highest precedence.-sOn Tue, Jul 23, 2013 at 8:16 AM, Cassiano Leal < " target="_blank"> > wrote:
I don’t think that’ll work if the default has been set.
What I mean is, say you have:
node.default[:myapp][:part1][:conf] = ‘XXX’
node.set[:myapp][:part1][:conf] ||= ‘XXX1’
This will probably set node[:myapp][:part1][:conf] to ‘XXX1’, since node.set[:myapp][:part1][:conf] was nil when the ||= operator kicked in.
I might be wrong and Chef might be doing some sourcery behind the scenes, but taking only Ruby into account, it wouldn’t work.
On July 23, 2013 at 05:21:59, Dorian Jaminais ( " target="_blank"> ) wrote:
ThanksBased on your response, my new work around is to define the component's attributes in two different hashes and have them merge into the default one.@Josiah : Thanks for the tip, I didn't know about the ||= operator.I was looking for a way to do that using the attribute files.
2013/7/23 Josiah Kiehl < " target="_blank"> >I would set this in the component's recipe:node.normal[:myapp][:part1][:conf] ||= "XXX1"||= will only set the attribute if the attribute has not yet been set.On Mon, Jul 22, 2013 at 5:08 PM, Daniel DeLeo < " target="_blank"> > wrote:
On Monday, July 22, 2013 at 10:15 AM, Dorian Jaminais wrote:
default["myapp"]["truc"] = "YYY"default["myapp"]["conf"] = "XXX"default.rbFor this reason I'd like to define 'default' attributes in the default attribute file and then have one attribute file per part of my application. Atribute would be organized this way :Most of thetime the configuration of both will be identical but this may not be always true.I have an application split in two components, each requiring its configuration.Here is my use case :Ohai Chefs !Is there a way in an attribute file to reuse attributes from another file ?
part1.rb
default["myapp"]["part1"]["conf"] = "XXX1"
#default["myapp"]["part1"]["truc"] = "YYY" < I want it to default to this value when not explicitly set
part2.rb
default["myapp"]["part2"]["conf"] = "XXX2"
Is there a way to achieve this ?At the moment I am using global variable to pass information from one file to the other but this seams ugly to me.Split the shared part out into another cookbook?--Daniel DeLeo
--
Archive powered by MHonArc 2.6.16.