如何在一个hos上运行@rolesdecorated fabric任务

2024-05-16 02:54:53 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个用@roles修饰的任务,我偶尔想在单个主机上运行(对于canary测试部署)。在

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 ^{}声明:

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

但是我不能让这里提到的“覆盖”功能工作。。。我试过:

^{pr2}$

但它总是在decorator中提到的整个角色上执行。。。在

我错过了什么?如何覆盖@roles修饰任务的运行位置?在


Tags: thedjangofromimportenvapiweb部署
1条回答
网友
1楼 · 发布于 2024-05-16 02:54:53

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

下面是一个不起作用的命令:

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

这个版本就是这样的:

^{pr2}$

问题是:#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.

相关问题 更多 >