There are multiple ways to check for the existence of a nested attribute in chef, and I'm not sure which is correct/best, and if any will result in empty attributes being stored on the node:
node[:parent] and node[:parent][:child]
node.attribute?(:parent) and node[:parent].attribute?(:child))
node[:parent].nil? and node[:parent][:child].nil?
It'd be greatly preferred to be able to check for the parent and child at the same time, but I don't know if that's possible. I am using Chef 10, not Chef 11, though answers explaining either are welcome.
if node['foo']['bar']['baz'] && shoulddoit?
will gobble up any programming errors indef shoulddoit?
that raise NoMethodError). And it will also rescue any NoMethodError raised by the "do the stuff i want" block. For the absolutely trivial case this works, but once the trivial case becomes complicated this greatly hinders the ability to debug anything. This solution should not be used. – Para