Why is Capistrano 3 not filtering when using "on role (: web)"?

I'm not sure if this is just a misunderstanding in Capistrano and Rake on my part, but I go through the Capistrano 3 pages (www.capistranorb.com) and some of these steps point out how to write servers and how to accomplish the main task : check_write_permissions .

My problem is that when I try to run the example code on my servers using the following server setup, I get unexpected results.

I have a config / deploy / production.rb file created as such:

server '10.1.28.90', roles: [:web, :app]
server '10.1.246.239', roles: [:db]

      

Then I created a task: check_write_permissions in lib / capistrano / tasks / access_check.rake. I made one small modification for "on role (: all)", so it will be "on role (: web)" instead.

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

      

When I run the task:

cap production check_write_permissions

      

OR

bundle exec cap production check_write_permissions

      

... I expect it to only execute the: check_write_permissions code on servers with: web role. Instead, my output shows that server: db is also started with the task: check_write_permissions. This throws exceptions because I don't have a deployment directory on the database server.

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 <wayneeseguin@gmail.com>, Michal Papis <mpapis@gmail.com> [https://rvm.io/]
DEBUG[fa4e93ec] Finished in 1.060 seconds with exit status 0 (successful).
rvm 1.25.28 (stable) by Wayne E. Seguin <wayneeseguin@gmail.com>, Michal Papis <mpapis@gmail.com> [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

      

When I run a task with a ROLE filter in the command I am executing, for example:

ROLES=web cap production check_write_permissions

      

This works as expected. I can see that only the webserver starts the task.

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 <wayneeseguin@gmail.com>, Michal Papis <mpapis@gmail.com> [https://rvm.io/]
DEBUG[7974b8ee] Finished in 1.062 seconds with exit status 0 (successful).
rvm 1.25.28 (stable) by Wayne E. Seguin <wayneeseguin@gmail.com>, Michal Papis <mpapis@gmail.com> [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

      

What is the reason for this? I dug up the Capistrano 3.2.1 code for a bit and I can't figure it out. Maybe it's just a misunderstanding on my part how roles (...) work, but I can't figure it out.

+3


source to share





All Articles