本文介绍了如何仅在单个主机上运行@roles装饰的Fabric任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用@roles装饰的任务,我有时希望在单个主机上运行(用于金丝雀测试部署).

I have a task decorated with @roles that I would occasionally like to run on a single host (for canary-testing deploys).

from fabric.api import *

env.roledefs = {
    'web-workers': ['django@worker1', 'django@worker2'],
    'some-other-role': ['django@worker2'],
}

@task
@roles('web-workers')
def bogomips():
    run('uptime')

@roles文档指出:

但是我无法使这里提到的替代"功能正常工作……我已经尝试过:

But I can't get the "override" functionality mentioned here to work... I've tried:

$ fab bogomips -H django@worker2
$ fab bogomips -R some-other-role

但是它总是在装饰器中提到的整个角色上执行...

but it always executes on the entire role mentioned in the decorator...

我在这里想念什么?如何覆盖装饰有@roles的任务的运行位置?

What am I missing here? How can I override where a @roles-decorated task is run?

推荐答案

根据执行模型的优先顺序,在这种情况下,您必须使用稍有不同的语法.

This is actually the intended behavior, according to the Execution model's Order of Precedence, and there's a slightly different syntax that you must use in this scenario.

所以这是不起作用的命令:

So here's the command that doesn't work:

$ fab bogomips -R some-other-role # fabric ignores the -R values!

这是可以工作的版本:

$ fab bogomips:roles=some-other-role

问题出在这里:#308:@roles和@hosts装饰器会忽略命令行选项

和文档: http://docs.fabfile.org/en/1.0.0/usage/execution.html#order-of-precedence

这篇关于如何仅在单个主机上运行@roles装饰的Fabric任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 13:15