Skip to content

Instantly share code, notes, and snippets.

@198d
Last active December 20, 2015 10:39
Show Gist options
  • Save 198d/6117122 to your computer and use it in GitHub Desktop.
Save 198d/6117122 to your computer and use it in GitHub Desktop.
from fabric.api import run, task, roles, env, execute
env.roledefs = {'web': ['host1.example.com',
'host2.example.com'],
'db': ['host3.example.com']}
@task
@roles('db')
def echo():
run('echo db')
@task
@roles('web')
def test():
run('echo web')
execute(echo)
$ fab test
[host1.example.com] Executing task 'test'
[host1.example.com] run: echo web
[host1.example.com] out: web
[host1.example.com] out:
[host3.example.com] Executing task 'echo'
[host3.example.com] run: echo db
[host3.example.com] out: db
[host3.example.com] out:
[host2.example.com] Executing task 'test'
[host2.example.com] run: echo web
[host2.example.com] out: web
[host2.example.com] out:
[host3.example.com] Executing task 'echo'
[host3.example.com] run: echo db
[host3.example.com] out: db
[host3.example.com] out:
Done.
Disconnecting from host1.example.com... done.
Disconnecting from host2.example.com... done.
Disconnecting from host3.example.com... done.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment