Skip to content

Instantly share code, notes, and snippets.

@sotarok
Created August 24, 2011 02:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sotarok/1167149 to your computer and use it in GitHub Desktop.
Save sotarok/1167149 to your computer and use it in GitHub Desktop.
inherit previous roles of a task for capistrano server selection.
# based on: http://pastie.org/293845
module Capistrano
class Configuration
module Servers
alias_method :original_find_servers, :find_servers
def find_servers(options={})
servers = original_find_servers options
stack_roles = task_call_frames.collect {|frame| frame.task.options[:roles]}.compact.flatten
servers = servers.select do |server|
if not stack_roles.empty?
stack_roles.any? { |role| self.roles[role].include?(server) }
else
true
end
end
servers.uniq
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment