0
votes

I working on chef which i needs to call attribute value from attributes/default.rb file to recipe/default.rb file. I am invoked attribute values in recipe which throws an error

undefined method [] for nil:NilClass`

Can someone help me on this.

# attribute/default.rb
default['app']['dir'] =  "/opt/app/"

# recipe/default.rb
ruby_block 'print_name' do
  block do
    puts "My app dir #{ node['app']['dir'] } "
  end
end
1
Did you copy&paste this? The code looks correct in terms of that you should be able to access this attribute. The failure indicates that node['app'] is nil instead of a Hash.StephenKing
i ran that code in the recipe file. but still i am facing nil class error. What is the solution for that. How to resolve it?palani.p
Can you share the code on Github or similar?StephenKing
Ah.. what's the name of the attributes directory? Is it really attribute/ as you write, or attributes/, as it is expected? Mind the trailing s!StephenKing
You need the plural for both attributes/ and recipes/.coderanger

1 Answers

0
votes

You can try writing like below in place of

puts "My app dir #{ node['app']['dir'] } "

write

puts "My app dir #{ node.default['app']['dir'] } "

default['app']['dir'] = "/opt/app/" #This is used in attributes/default.rb

This is priority. node.overwrite > node.normal > node.default