Skip to content

Instantly share code, notes, and snippets.

@amitsaha
Created August 7, 2012 02:28
Show Gist options
  • Select an option

  • Save amitsaha/3280808 to your computer and use it in GitHub Desktop.

Select an option

Save amitsaha/3280808 to your computer and use it in GitHub Desktop.
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

amitsaha commented Aug 7, 2012

Copy link
Copy Markdown
Author

Ignore the unused imports, btw.

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