Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Stubbed-Search (Chef)
module StubbedSearch
def stubbed_search(index, query, stub)
# When running in the 'local' environment, dynamically set the hostname
# value for the search_stub to the hostname of the running VM
if node.chef_environment == 'local'
node.normal[:search_stub][stub] = node[:search_stub][stub].map do |n|
hsh = n.to_hash
hsh[:hostname] = node[:hostname]
hsh
end
end
stub_results = node[:search_stub][stub] || []
if node[:search_stub][:disable_search][stub]
search_results = []
else
search_results = search(index, query)
end
if search_results.empty?
Chef::Log.info "stubbed_search for #{stub} using stub results"
stub_results
else
Chef::Log.info "stubbed_search for #{stub} using search results"
search_results
end
end
end
class Chef::Recipe
include StubbedSearch
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.