2014-03-25 32 views
3

这是我在配置production.rb /部署如何为特定角色创建角色并运行Capistrano任务?

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

我哪里去错了? 什么是正确的方法?

回答

1

我相信你想要的是cap HOSTFILTER=198.61.228.160 function_2cap HOSTFILTER=198.61.179.237 function_1

这是因为HOSTFILTER检查所有的功能作用,你要寻找的服务器的服务器的相交。一个伟大的解释可以通过Pete Hodgson

找到here此外,我们可以看到,因为手册中本:

$ 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. 
相关问题