fab -f tset.py show catmem
from fabric.api import *
env.hosts = ['192.168.1.112','chang']
env.user = 'root'
env.password = '1'
env.port = 22
@task
def show():
run('hostname')
run('netstat -tnulp |grep 22')
run('ls /root/')
@task
def catmem():
run('free -m')
@task
def run_all():
execute(show)
execute(cateme)
if __name__ == '__main__':
execute(run_all)
fab -f test2.py -l 显示任务列表
(venv) os@ubuntu:/mnt/osfabric$ fab -f test2.py -l
Available commands:
ifconfig
show
from fabric.api import *
env.hosts = ['192.168.1.112','chang']
env.user = 'root'
env.roledefs ={
'webserver':['192.168.1.112'],
'dbserver':['chang']
}
@task
def show():
run('hostname')
@task
@roles('dbserver')
def ifconfig():
run('ifconfig')
@task
def run_all():
execute(show)
execute(ifconfig)
if __name__ == "__main__":
execute(run_all)