1. Create File auto_install_mysql.py
Vim auto_install_mysql.py
-------------------------------------------->
1#!/usr/bin/env python2 3 fromFabric.colors Import *4 fromFABRIC.API Import *5Env.user='Root'6Env.roledefs = {7 'DBServer': ['172.16.1.207']//Here you can add more than one host8 }9Env.password = {Ten '[email protected]':'Redhat' One } A -@roles ('DBServer') - def dbtask (): thePrint yellow ("Install mysql-server ...") -With settings (warn_only=True): -Run"apt-get Install mysql-server-y") -Run"Service MySQL Restart") + - def deploy (): +Execute (dbtask)//Here you can add multiple tasks
2. Execution of documents
Fab-f auto_install_mysql.py Deploy
The results of the implementation are as follows:
To enter the password interface, enter the password, then press the TAB key to jump to OK, and then press the SPACEBAR to set
Fabric Automation Installation Mysql-server