[chef] Re: Re: node.attribute? check nested


Chronological Thread 
  • From: Ranjib Dey < >
  • To:
  • Cc: Daniil S < >
  • Subject: [chef] Re: Re: node.attribute? check nested
  • Date: Sun, 14 Jul 2013 09:43:23 -0700

this will bork , if node['foo'] is nil, 

im not aware of anything from chef api, but i know  this is a very common requirement,  I tend to use a helper method, like this :

def nested_attrbs?(*args)
  ret = true
   n = node
  args.each do |nesting|
    unless n.attribute?(nesting)
       ret = false
       break
     else
       n = n[nesting]
     end 
  end
  ret
end



On Sun, Jul 14, 2013 at 9:24 AM, Nic Grayson < " target="_blank"> > wrote:
node['foo']['bar'] is just a variable so any ruby logic will work

puts "it's not set" unless node['foo']['bar']

if node['foo']['bar'] == "biz" etc.


On Sun, Jul 14, 2013 at 11:02 AM, Daniil S < " target="_blank"> > wrote:
Hello.
Official documentation mentions such construction:
not_if { node.attribute?("some_command_complete") }

Can I check nested attribute with it?
For example, if i have attribute node['foo']['bar'], how can i check if it is set?





Archive powered by MHonArc 2.6.16.

§