Chef - Find the Missing NilClass Attribute

Context . We have a huge number of chef attributes to complete our setup, now something like 3000+ is defined and changed for each environment.

Problem . Sometimes a chef's recipe will refer to a nonexistent attribute node[:mystuff][:typo]. This results in the following error:

Recipe Compile Error in /var/chef/cache/cookbooks/<yyy>/recipes/something.rb
undefined method '[]' for nil:NilClass

This is a useless error because it does not allow me to know for sure that node / attribute is missing. Even working with chef-client -l debugdoes not help. knife cookbook test <x>doesn't help, because syntactically it's correct. Is there a way to get it to print the exact line number causing the error? A recipe can contain 10 or 100 attributes, so this is a huge waste of time going through the lines to find a typo.

+4
source share
1 answer

I wrote the Chef Sugar deep_fetch method for exactly this reason.

The error you get is just a byproduct of Ruby hashes. For more information about deep_fetch, you can also see my blog post on the topic: https://sethvargo.com/delicious-new-chef-sugars/

+6
source

Source: https://habr.com/ru/post/1531404/


All Articles