gpt4 book ai didi

python - 如何仅在单个主机上运行 @roles-decorated 结构任务

转载 作者:行者123 更新时间:2023-12-01 03:27:33 24 4
gpt4 key购买 nike

我有一个用 @roles 装饰的任务,我偶尔想在单个主机上运行它(用于金丝雀测试部署)。

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')

docs for @roles指出:

...barring an override on the command line, my_func will be executed against the hosts listed [in the role]...

但是我无法让此处提到的“覆盖”功能起作用......我已经尝试过:

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

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

我在这里缺少什么?如何覆盖 @roles 修饰的任务的运行位置?

最佳答案

根据Execution model's Order of Precedence,这实际上是预期的行为,并且在此场景中您必须使用稍微不同的语法。

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

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

这是有效的版本:

$ fab bogomips:roles=some-other-role

问题如下:#308: @roles and @hosts decorators ignore command line options

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

  • Per-task, command-line host lists (fab mytask:host=host1) override absolutely everything else.
  • Per-task, decorator-specified host lists (@hosts('host1')) override the env variables.
  • Globally specified host lists set in the fabfile (env.hosts = ['host1']) can override such lists set on the command-line, but only if you’re not careful (or want them to.)
  • Globally specified host lists set on the command-line (--hosts=host1) will initialize the env variables, but that’s it.

关于python - 如何仅在单个主机上运行 @roles-decorated 结构任务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41291940/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com