title: Why does Capistrano 3 not filter when using "on roles(:web)"?
body: <p>I'm not sure if this is just a misunderstanding on Capistrano and Rake on my part, but I'm going through the Capistrano 3 set up pages (www.capistranorb.com) and a few of the steps mention how to write up the servers and how to run the basic task of <strong>:check_write_permissions</strong>.</p>
  
  <p>My problem is when I try to run the example code on my servers using the following server setup, I get unexpected results.</p>
  
  <p>I have my <em>config/deploy/production.rb</em> file set up as such:</p>
  
  <pre><code>server '10.1.28.90', roles: [:web, :app]
  server '10.1.246.239', roles: [:db]
  </code></pre>
  
  <p>I then created the :check_write_permissions task in <em>lib/capistrano/tasks/access_check.rake</em>. I made one small modification to the "on roles(:all)" so it would instead be "on roles(:web)".</p>
  
  <pre><code>desc "Check that we can access everything"
  task :check_write_permissions do
    on roles(:web) do |host|
      if test("[ -w #{fetch(:deploy_to)} ]")
        info "#{fetch(:deploy_to)} is writable on #{host}"
      else
        error "#{fetch(:deploy_to)} is not writable on #{host}"
      end
    end
  end
  </code></pre>
  
  <p>When I run the task:</p>
  
  <pre><code>cap production check_write_permissions
  </code></pre>
  
  <p>OR</p>
  
  <pre><code>bundle exec cap production check_write_permissions
  </code></pre>
  
  <p>... I am expecting that it will only run the :check_write_permissions code against the servers with a :web role. Instead, my output show that the :db server is also run against with the :check_write_permissions task. This throws exceptions because I do not have a deploy directory on the database server.</p>
  
  <pre><code>DEBUG[90f77252] Running /usr/local/rvm/bin/rvm version on 10.1.246.239
  DEBUG[90f77252] Command: /usr/local/rvm/bin/rvm version
  DEBUG[fa4e93ec] Running /usr/local/rvm/bin/rvm version on 10.1.28.90
  DEBUG[fa4e93ec] Command: /usr/local/rvm/bin/rvm version
  DEBUG[90f77252]     bash: /usr/local/rvm/bin/rvm: No such file or directory
  DEBUG[fa4e93ec]     rvm 1.25.28 (stable) by Wayne E. Seguin &lt;wayneeseguin@gmail.com&gt;, Michal Papis &lt;mpapis@gmail.com&gt; [https://rvm.io/]
  DEBUG[fa4e93ec] Finished in 1.060 seconds with exit status 0 (successful).
  rvm 1.25.28 (stable) by Wayne E. Seguin &lt;wayneeseguin@gmail.com&gt;, Michal Papis &lt;mpapis@gmail.com&gt; [https://rvm.io/]
  DEBUG[3583646b] Running /usr/local/rvm/bin/rvm current on 10.1.28.90
  DEBUG[3583646b] Command: /usr/local/rvm/bin/rvm current
  DEBUG[3583646b]     ruby-2.0.0-p481
  DEBUG[3583646b] Finished in 0.286 seconds with exit status 0 (successful).
  ruby-2.0.0-p481
  DEBUG[b91aa735] Running /usr/local/rvm/bin/rvm 2.0.0-p481 do ruby --version on 10.1.28.90
  DEBUG[b91aa735] Command: /usr/local/rvm/bin/rvm 2.0.0-p481 do ruby --version
  DEBUG[b91aa735]     ruby 2.0.0p481 (2014-05-08 revision 45883) [x86_64-linux]
  DEBUG[b91aa735] Finished in 0.400 seconds with exit status 0 (successful).
  ruby 2.0.0p481 (2014-05-08 revision 45883) [x86_64-linux]
  cap aborted!
  SSHKit::Runner::ExecuteError: Exception while executing on host 10.1.246.239: rvm exit status: 127
  rvm stdout: Nothing written
  rvm stderr: bash: /usr/local/rvm/bin/rvm: No such file or directory
  </code></pre>
  
  <p>When I run the task with a ROLE filter in the command I execute, such as:</p>
  
  <pre><code>ROLES=web cap production check_write_permissions
  </code></pre>
  
  <p>This works as expected. I see only the web server get the task run against it.</p>
  
  <pre><code>DEBUG[7974b8ee] Running /usr/local/rvm/bin/rvm version on 10.1.28.90
  DEBUG[7974b8ee] Command: /usr/local/rvm/bin/rvm version
  DEBUG[7974b8ee]     rvm 1.25.28 (stable) by Wayne E. Seguin &lt;wayneeseguin@gmail.com&gt;, Michal Papis &lt;mpapis@gmail.com&gt; [https://rvm.io/]
  DEBUG[7974b8ee] Finished in 1.062 seconds with exit status 0 (successful).
  rvm 1.25.28 (stable) by Wayne E. Seguin &lt;wayneeseguin@gmail.com&gt;, Michal Papis &lt;mpapis@gmail.com&gt; [https://rvm.io/]
  DEBUG[23f666d8] Running /usr/local/rvm/bin/rvm current on 10.1.28.90
  DEBUG[23f666d8] Command: /usr/local/rvm/bin/rvm current
  DEBUG[23f666d8]     ruby-2.0.0-p481
  DEBUG[23f666d8] Finished in 0.297 seconds with exit status 0 (successful).
  ruby-2.0.0-p481
  DEBUG[7ae64240] Running /usr/local/rvm/bin/rvm 2.0.0-p481 do ruby --version on 10.1.28.90
  DEBUG[7ae64240] Command: /usr/local/rvm/bin/rvm 2.0.0-p481 do ruby --version
  DEBUG[7ae64240]     ruby 2.0.0p481 (2014-05-08 revision 45883) [x86_64-linux]
  DEBUG[7ae64240] Finished in 0.387 seconds with exit status 0 (successful).
  ruby 2.0.0p481 (2014-05-08 revision 45883) [x86_64-linux]
  DEBUG[c0ebccc0] Running /usr/bin/env [ -w /data/union_benefits/ ] on 10.1.28.90
  DEBUG[c0ebccc0] Command: [ -w /data/union_benefits/ ]
  DEBUG[c0ebccc0] Finished in 0.126 seconds with exit status 1 (failed).
  ERROR/data/union_benefits/ is not writable on 10.1.28.90
  </code></pre>
  
  <p>What is the reason behind this? I have dug through the Capistrano 3.2.1 code a bit and I cannot figure this out. Maybe this is just a misunderstanding on my part of how the roles(...) work, but I can't figure it out.</p>