首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何为特定角色创建角色并运行capistrano任务?

如何为特定角色创建角色并运行capistrano任务?
EN

Stack Overflow用户
提问于 2014-03-25 15:41:46
回答 1查看 1.2K关注 0票数 3

下面是我在production.rb /deploy中的配置

代码语言:javascript
复制
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

代码语言:javascript
复制
namespace :check do
  task :function_1, :roles => :web do
    puts 'function_1'
  end
  task :function_2, :roles => :file_server do
    puts 'filesssss'
  end
end

但当我试着做

代码语言:javascript
复制
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

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

EN

回答 1

Stack Overflow用户

发布于 2014-06-10 21:42:19

我相信你想要的是cap HOSTFILTER=198.61.228.160 function_2或者cap HOSTFILTER=198.61.179.237 function_1

这是因为HOSTFILTER检查所有具有函数、角色和您要查找的服务器的服务器的交集。一个很好的解释可以在Pete Hodgson上找到here

我们也可以从手册中看到这一点:

代码语言:javascript
复制
    $ 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.
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22628208

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档