【问题标题】:How to create roles and run capistrano tasks for specific roles?如何为特定角色创建角色并运行 capistrano 任务?
【发布时间】:2014-05-02 22:04:29
【问题描述】:

这是我在配置/部署中的 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

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

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-4 capistrano roles role


    【解决方案1】:

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

    这是因为 HOSTFILTER 检查所有具有功能角色的服务器和您正在寻找的服务器的交集。 here by 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.
    

    【讨论】:

      猜你喜欢
      • 2011-09-25
      • 2016-11-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-05
      • 1970-01-01
      • 2019-01-14
      相关资源
      最近更新 更多