有多种方法可以检查 chef 中是否存在嵌套属性,我不确定哪个是正确/最好的,如果有的话会导致节点上存储空属性:
node[:parent] and node[:parent][:child]
node.attribute?(:parent) and node[:parent].attribute?(:child))
node[:parent].nil? and node[:parent][:child].nil?
最好能够同时检查父母和孩子,但我不知道这是否可能。我使用的是 Chef 10,而不是 Chef 11,但欢迎提供任何解释的答案。