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')
The docs for @roles
states that:
...barring an override on the command line, my_func will be executed against the hosts listed [in the role]...
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...
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:
And here's the version that DOES work:
Here's the issue: #308: @roles and @hosts decorators ignore command line options
And the docs: http://docs.fabfile.org/en/1.0.0/usage/execution.html#order-of-precedence