Created
September 11, 2014 16:55
-
-
Save bmhatfield/e49022dbea8013c3cef4 to your computer and use it in GitHub Desktop.
Stubbed-Search (Chef)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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