capistrano/capistrano — Issue #137: ENV['HOSTS'] filter ignores role restricted tasks
Author: pivotal-casebook
Created: 2011-12-19 19:26:18+00:00
State: open

Given the following deploy.rb:

role :web, "one"
role :app, "two"
role :db, "three"

task :foo, :roles => [:app, :web] do
puts "Foo: #{find_servers_for_task(tasks[:foo]).map(&:host).map(&:to_s).join(',')}"
end

task :bar do
puts "Bar: #{find_servers_for_task(tasks[:bar]).map(&:host).map(&:to_s).join(',')}"
end

task :baz, :roles => [:db] do
puts "Baz: #{find_servers_for_task(tasks[:baz]).map(&:host).map(&:to_s).join(',')}"
end

before :bar, :foo

Then run the following:

$ cap bar
* executing `bar'
triggering before callbacks for `bar'
* executing `foo'
Foo: two,one
Bar: three,one,two

$ cap bar HOSTS=three
* executing `bar'
triggering before callbacks for `bar'
* executing `foo'
Foo: three
Bar: three

Why is it now invoking foo for three? So if I use the HOSTS filter, it will now ignore any task restrictions based on role. Certainly that cannot be the intended behavior with the HOSTS filter.