2014-03-25 39 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. 
相關問題