Fabric實現自動化部署
阿新 • • 發佈:2018-06-09
word bsp python 端口 yum TE prompt .py class
Fabric實現自動化部署
1. 安裝fabric
yum install fabric -y
2. 編寫腳本來實現自動化部署
註意:env.passwords中要指明端口22,以及多個用戶用逗號隔開
遠程102,103兩臺主機執行 ls -l 目錄
#cat frbfile.py from fabric.api import *
env.hosts = [‘192.168.12.102‘,‘192.168.12.103‘] env.passwords = { ‘[email protected]:22‘:‘redhat‘, ‘[email protected]:22‘:‘redhat‘, }
@runs_once def input_raw(): return prompt(‘please input you dir:>>>‘) def runs(dirN): run(‘ls -l ‘ + dirN) @task def test(): dirname = input_raw() runs(dirname) print(‘END.....‘)
Fabric實現自動化部署