-
-
Save Farzy/456040 to your computer and use it in GitHub Desktop.
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
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