Chef

From Sigmon

Jump to: navigation, search

Quick Cheetsheet

More documents here, http://wiki.opscode.com/display/chef/Just+Enough+Ruby+for+Chef

@variable in template
variable in recipe

@node always refers to the current node in template

constants start with upper case letter
private variables start with lower case variable



Code

Demo of some ruby code

    def search(type, query, attributes=[], &block)
      Chef::Log.debug("Searching #{type} index with #{query}")
      r = Chef::REST.new(Chef::Config[:search_url])

      results = r.get_rest("search/#{type}?q=#{query}&a=#{attributes.join(',')}")
      Chef::Log.debug("Searching #{type} index with #{query} returned #{results.length} entries")
      if block
        results.each do |sr|
          block.call(sr)
        end
      else
        results
      end
    end
Personal tools