Ruby on rails 如何为特定角色创建角色并运行capistrano任务?
这是我在config/deploy中的production.rbRuby on rails 如何为特定角色创建角色并运行capistrano任务?,ruby-on-rails,ruby-on-rails-4,capistrano,roles,role,Ruby On Rails,Ruby On Rails 4,Capistrano,Roles,Role,这是我在config/deploy中的production.rb Instance Details server '198.61.179.237', :web, :app, :db, primary: true server '198.61.228.160', :file_server # Rails Environment set :rails_env, 'production' 从deploy.rb namespace :check do task :function_1, :rol
Instance Details
server '198.61.179.237', :web, :app, :db, primary: true
server '198.61.228.160', :file_server
# Rails Environment
set :rails_env, 'production'
从deploy.rb
namespace :check do
task :function_1, :roles => :web do
puts 'function_1'
end
task :function_2, :roles => :file_server do
puts 'filesssss'
end
end
但是当我试着做
cap HOSTS=198.61.228.160 production check:function_2
cap HOSTS=198.61.228.160 production check:function_1
cap HOSTS=198.61.179.237 production check:function_2
cap HOSTS=198.61.179.237 production check:function_1
他们每个人都给出了各自的输出。但是根据声明
函数_1
应仅适用于:角色=>:web
,同样地函数_2
应仅适用于:角色=>:文件服务器
我错在哪里?
正确的方法是什么?我相信您想要的是
cap HOSTFILTER=198.61.228.160函数_2
或cap HOSTFILTER=198.61.179.237函数_1
这是因为HOSTFILTER检查所有具有函数角色的服务器与您要查找的服务器的交集。一个很好的解释可以通过
由于手册的原因,我们也可以看到这一点:
$ cap -H
HOSTS
Execute the tasks against this comma-separated list of hosts.
Effectively, this makes the host(s) part of every roles.
HOSTFILTER
Execute tasks against this comma-separated list of host,
but only if the host has the proper role for the task.
HOSTROLEFILTER
Execute tasks against the hosts in this comma-separated list of roles,
but only if the host has the proper role for the task.
ROLES
Execute tasks against this comma-separated list of roles. Hosts which
do not have the right roles will be skipped.