fabric自動化安裝mysql-server
阿新 • • 發佈:2017-08-10
role roles bin tin true pan service http cut
1、創建文件auto_install_mysql.py
vim auto_install_mysql.py
-------------------------------------------->
1 #!/usr/bin/env python 2 3 from fabric.colors import * 4 from fabric.api import * 5 env.user=‘root‘ 6 env.roledefs = { 7 ‘dbserver‘: [‘172.16.1.207‘] //此處可以添加多臺主機 8 } 9 env.password = {10 ‘[email protected]‘: ‘redhat‘ 11 } 12 13 @roles(‘dbserver‘) 14 def dbtask(): 15 print yellow("Install mysql-server ...") 16 with settings(warn_only=True): 17 run("apt-get install mysql-server -y") 18 run("service mysql restart") 19 20 def deploy(): 21 execute(dbtask) //此處可以添加多個任務
2、執行文件
fab -f auto_install_mysql.py deploy
執行結果如下:
執行到輸入密碼的界面時,輸入密碼,然後按tab鍵跳到ok處,接著按空格鍵設置
fabric自動化安裝mysql-server