我正在嘗試爲簡化一些常見搜索的廚師食譜編寫一個庫。如何從廚師食譜的圖書館訪問當前節點?
例如,我希望能夠做這樣的事在cookbook/libraries/library.rb
,然後在相同的食譜使用它從配方:
module Example
def self.search_attribute(attribute_name)
return search(:nodes, node[attribute_name])
end
end
的問題是,一個廚師庫文件中node
對象或search
函數都不可用。
搜索似乎有可能通過使用Chef::Search::Query.new().search(...)
,但我找不到任何作品訪問node
。由此產生的錯誤是:
undefined local variable or method `node' for Example:Module
使用廚師10.16.4。
相關http://stackoverflow.com/a/22081109/1626687 – spuder