????3. ????????fabfile.py?????????
????# mv fabfile.py test.py
????# fab hello
????Fatal error: Couldn't find any fabfiles!
????Remember that -f can be used to specify fabfile path?? and use -h for help.
????# fab -f test.py hello
????Hello fab!
????4. ????????
????#vi fabfile.py
????def hello(name):
????print 'Hello %s!'%name
????# fab hello:name=fab
????Hello fab!
????# fab hello:fab
????Hello fab!
????2.2.    ???????
??????б?????????????local
????1. fabfile.py???????????
????from fabric.api import local
????def test():
????local('cd /home/')
????local('ls -l|wc -l')
????2. ???????fab test?????????
????# fab test
????[localhost] local: cd /home/
????[localhost] local: ls -l|wc -l
????2.3.    ??????
????????????????????run
????1. fabfile.py???????????
????from fabric.api import cd??run??env??hosts
????env.hosts=['192.168.85.99:22'??'192.168.85.101:22']
????env.password='test'
????def test():
????with cd('/home'):
????run("du -sh")
????2. ???????fab test?????????
????# fab test
????[192.168.85.99:22] Executing task 'test'
????[192.168.85.99:22] run: du -sh
????[192.168.85.99:22] out: 392G      .
????[192.168.85.99:22] out:
????[192.168.85.101:22] Executing task 'test'
????[192.168.85.101:22] run: du -sh
????[192.168.85.101:22] out: 5.6G     .
????[192.168.85.101:22] out:
????Disconnecting from 192.168.85.99... done.
????Disconnecting from 192.168.85.101... done.
????3. ???????????????????????????в???????????ο???????
????from fabric.api import env??roles??run??execute
????env.roledefs = {
????'server1': ['root@192.168.85.99:22'??]??
????'server2': ['root@192.168.85.100:22'?? ]
????}
????env.password = 'test'
????@roles('server1')
????def task1():
????run('ls /home/ -l | wc -l')
????@roles('server2')
????def task2():
????run('du -sh /home')
????def test():
????execute(task1)
????execute(task2)
???????????

 

????# fab test
????[root@192.168.85.99:22] Executing task 'task1'
????[root@192.168.85.99:22] run: ls /home/ -l | wc -l
????[root@192.168.85.99:22] out: 27
????[root@192.168.85.99:22] out:
????[root@192.168.85.100:22] Executing task 'task2'
????[root@192.168.85.100:22] run: du -sh /home
????[root@192.168.85.100:22] out: 1.4G   /home
????[root@192.168.85.100:22] out:
????Disconnecting from 192.168.85.99... done.
????Disconnecting from 192.168.85.100... done.