Skip to content

Instantly share code, notes, and snippets.

@Bouke
Created September 16, 2012 12:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Bouke/3732305 to your computer and use it in GitHub Desktop.
Save Bouke/3732305 to your computer and use it in GitHub Desktop.
fabric test: hosts/roles command line overrides
from fabric.api import *
## hosts
@task
@hosts('a')
def first():
execute(second)
@task
@hosts('b')
def second():
pass
# $ fab first
# [a] Executing task 'first'
# [b] Executing task 'second'
# $ fab first -H c
# [a] Executing task 'first'
# [b] Executing task 'second'
# $ fab first:hosts=c
# [c] Executing task 'first'
# [b] Executing task 'second'
## roles
env.roledefs = {
'd': ['host-d'],
'e': ['host-e'],
}
@task
@roles('d')
def third():
execute(forth)
@task
@roles('e')
def forth():
pass
# $ fab third
# [host-d] Executing task 'third'
# [host-e] Executing task 'forth'
# $ fab third -H c
# [host-d] Executing task 'third'
# [host-e] Executing task 'forth'
# $ fab third:hosts=c
# [c] Executing task 'third'
# [host-e] Executing task 'forth'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment