有多种方法可以检查chef中是否存在嵌套属性,我不确定哪个是正确/最好的,如果有的话会导致在节点上存储空属性:
node[:parent] and node[:parent][:child]
node.attribute?(:parent) and node[:parent].attribute?(:child))
node[:parent].nil? and node[:parent][:child].nil?
Run Code Online (Sandbox Code Playgroud)
能够同时检查父母和孩子是非常优先的,但我不知道是否可能.我正在使用厨师10,而不是厨师11,尽管答案解释任何一个都是受欢迎的.
我正在尝试为厨师食谱编写一个库,简化了一些常见搜索.
例如,我希望能够做同样的事情cookbook/libraries/library.rb,然后在同一本食谱中的食谱中使用它:
module Example
def self.search_attribute(attribute_name)
return search(:nodes, node[attribute_name])
end
end
Run Code Online (Sandbox Code Playgroud)
问题是,在Chef库文件中,node对象或search函数都不可用.
搜索似乎可以通过使用Chef::Search::Query.new().search(...),但我找不到任何有效的访问node.由此产生的错误是:
undefined local variable or method `node' for Example:Module
Run Code Online (Sandbox Code Playgroud)
使用Chef 10.16.4.
Chef :: Version包含Chef gem的版本号,我想检查它是否符合~> 10.14配方内的gem要求.
我有一个从厨师搜索返回的节点列表,它将用于创建配置文件.这些节点需要订购,因为