背景
破法
- 采用python的fabric
- file文件结构如下
头部
#!/usr/bin/python
from fabric.api import *
from fabric.context_managers import *
from fabric.contrib.console import confirm
import time,os
A - 机器列表
a1='root@xxx'
a2='root@xxx'
a3='root@xxx'
a4='root@xxx'
env.passwords = {
a1:'xxx',
a2:'xxx',
a3:'xxx'
}
env.roledefs = {
'r1':[a1],
'r2':[a1,a2],
'r3':[a1,a3],
'r4':[a4]
}
B - 基本函数定义
def project_package(path, name):
with lcd(path):
local("mvn clean package -Dmaven.test.skip=true -P prod,"+name)
def project_install(path):
with lcd(path):
local("mvn clean install -Dmaven.test.skip=true -P prod")
def project_deploy(path):
with lcd(path):
local("mvn clean deploy -Dmaven.test.skip=true -P prod")
C - 组合函数定义
def deploy_to_tomcat(dir, name, port):
project_update(dir)
project_package(dir, name)
project_tomcat_stop(port)
project_web_bak(dir)
project_web_clean(dir+name)
project_put(dir+name+"/target/"+name+"-1.0.war", dir+name+"ROOT.war")
project_tomcat_start(dir)
D – 定义Task
@task
@roles('r1')
def t1():
dir = env.basepath + "t1"
deploy_to_tomcat(dir,'t1', '6770')