fabric

来源:互联网 发布:mysql自带可视化界面 编辑:程序博客网 时间:2024/04/20 09:27
fab -f tset.py show catmem#coding:utf8from fabric.api import *env.hosts = ['192.168.1.112','chang']env.user = 'root'env.password = '1'env.port = 22@taskdef show():    run('hostname')    run('netstat -tnulp |grep 22')    run('ls /root/')@taskdef catmem():    run('free -m')@taskdef 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 -lAvailable commands:    ifconfig    show
#coding:utf-8from fabric.api import *env.hosts = ['192.168.1.112','chang']env.user = 'root'env.roledefs ={    'webserver':['192.168.1.112'],    'dbserver':['chang']}@taskdef show():    run('hostname')@task@roles('dbserver')def ifconfig():    run('ifconfig')@taskdef run_all():    execute(show)    execute(ifconfig)if __name__ == "__main__":    execute(run_all)
原创粉丝点击