Skip to content

Instantly share code, notes, and snippets.

@amitsaha
Created August 7, 2012 02:28
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
Nested Fabric tasks
import os
from fabric.api import task, run, hosts, cd, env, local
from fabric.operations import put
@task
@hosts('root@10.0.0.9')
def host1task():
put(os.path.abspath('fabfile1.py'),'/tmp/')
run('fab -f /tmp/fabfile1.py host2task')
from fabric.api import task, run, hosts, cd, env, local
from fabric.operations import put
@task
@hosts('root@10.0.0.27')
def host2task():
run('uname -a')
[gene@zion64 ~]$ fab -f /home/gene/fabfile.py host1task
[root@10.0.0.9] Executing task 'host1task'
[root@10.0.0.9] Login password for 'root':
[root@10.0.0.9] put: /home/gene/fabfile1.py -> /tmp/fabfile1.py
[root@10.0.0.9] run: fab -f /tmp/fabfile1.py host2task
[root@10.0.0.9] out: [root@10.0.0.27] Executing task 'host2task'
[root@10.0.0.9] out: [root@10.0.0.27] run: uname -a
[root@10.0.0.9] out: [root@10.0.0.27] Login password for 'root':
[root@10.0.0.9] out: [root@10.0.0.27] out: Linux zion64 3.5.0-2.fc17.x86_64 #1 SMP Mon Jul 30 14:48:59 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux
[root@10.0.0.9] out: Done.
[root@10.0.0.9] out: Disconnecting from 10.0.0.27... done.
Done.
Disconnecting from root@10.0.0.9... done.
@amitsaha
Copy link
Author

amitsaha commented Aug 7, 2012

Ignore the unused imports, btw.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment