title: How can I access the current node from a library in a Chef cookbook?
body: <p>I'm attempting to write a library for a chef cookbook that simplifies some common searches.</p>
  
  <p>For example, I'd like to be able to do something like this in <code>cookbook/libraries/library.rb</code> and then use it from a recipe in the same cookbook:</p>
  
  <pre><code>module Example
      def self.search_attribute(attribute_name)
          return search(:nodes, node[attribute_name])
      end
  end
  </code></pre>
  
  <p>The problem is that, inside a Chef library file neither the <code>node</code> object or <code>search</code> function are available.</p>
  
  <p>Search seems to be possible by using <code>Chef::Search::Query.new().search(...)</code>, but I can't find anything that works to access <code>node</code>. The resulting error from this is:</p>
  
  <pre><code>undefined local variable or method `node' for Example:Module
  </code></pre>
  
  <p>Using Chef 10.16.4.</p>