On my project we do this sort of thing 2 different ways.
The preferred way is what Lee's talking about, where we manage
environment specific tasks with after/before hooks in the stage files
(we do the load of a separate cap file as well).
But if we have something that strategy feels weird for (whether it's
ok for it to not match anything, or it'd be a pain to do it as a
hook), we use the following:
http://gist.github.com/246376
module Capistrano
class Configuration
module Namespaces
def skippable_task(name, *args, &block)
task name, *args do
if find_servers_for_task(current_task).empty?
logger.info "skipping #{current_task.fully_qualified_name}
since it matches no servers"
else
block.call
end
end
end
end
end
end
You just need to put that in a file and require it somewhere in your
deploy. Then, for tasks that you want to skip instead of saying:
task :some_task, :roles => :app do
# ...
end
you'd say:
skippable_task :some_task, :roles => :app do
#...
end
The exact cases we use this for are when the task we want to skip is
nested deep in something else, and it'd be confusing to have to
remember exactly which hook to embed where.