The ROLES environment variable is an override, not a filter. This means
it will force all tasks that run, to run on the given roles.
There is not currently a way to specify a role filter. If you really
want that task to run ONLY on the servers in role2, you'd need to
manually guard that task:
task :my_custom_task, :roles => :role2 do
servers = find_servers_for_task(current_task) & roles[:role2].servers
run "whatever", :hosts => servers if servers.any?
end
What that does is find all the servers that capistrano WANTS to execute
the task on (via find_servers_for_task), intersects that with the
servers in role2, and then runs the command against those servers,
explicitly.
You can tell this is a use case that Capistrano was not designed for. :/
- Jamis