Skip to content

Instantly share code, notes, and snippets.

@Farzy
Forked from octplane/cookbook.rb
Created June 28, 2010 16:16
Show Gist options
  • Save Farzy/456040 to your computer and use it in GitHub Desktop.
Save Farzy/456040 to your computer and use it in GitHub Desktop.
class Chef
module Mixin
module Language
# esearch(:node, 'role\[admin\]')
# recursively search for this role/recipe in all roles
def esearch(context, search)
if context == :role
ret = []
# First solve all roles:
roles = search(:role, search)
if not roles.nil?
roles.each do |role|
ret << esearch(:role, "run_list:role\\[#{role.name}\\]")
end
end
ret << roles
return ret.flatten
elsif context == :node
# Find all roles including this recipe
nodes = []
roles = esearch(:role, "run_list:"+search)
roles.each do |r|
nodes << search(:node, "run_list:role\\[#{r.name}\\]")
end
nodes.flatten!
nodes.sort!
# Unify by to_s value
nodes = nodes.inject({}) do |hash,item|
hash[item.to_s]||=item
hash
end.values
return nodes
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment