这是我在配置/部署中的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, :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
每个人都给出各自的输出。但是根据声明
function_1
应该仅适用于:role => :web
,类似地function_2
应该仅适用于:role => :file_server
。我要去哪里错了?
正确的处理方法是什么?
最佳答案
我相信您想要的是cap HOSTFILTER=198.61.228.160 function_2
或cap HOSTFILTER=198.61.179.237 function_1
这是因为HOSTFILTER会检查所有具有功能角色的服务器和您要查找的服务器的交集。 here可以找到一个很好的解释Pete Hodgson
由于手册,我们也可以看到以下内容:
$ 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.