1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
| # -*- coding:utf-8 -*-
#! /usr/bin/env python
from fabric.api import *
from fabric.colors import *
from fabric.context_managers import *
from fabric.contrib.console import confirm
import time
env.port= '22'
env.user='root'
env.password='123456'
env.roledefs = {
'get-server': ['192.168.64.128',],
'put-seever': ['192.168.64.131',],
}
env.project_nginx_conf = '/soft/nginx.conf'
env.deploy_nginx_conf = '/usr/local/nginx/conf/nginx.conf'
@task
@roles('get-server')
def get_file():
print yellow("Start get configuration file ...")
result = get(env.deploy_nginx_conf,env.project_nginx_conf)
if result.failed and no("get file failed, Continue[Y/N]?"):
abort("Aborting file get task!")
print green("get to configuration files successfully!")
@task
@roles('put-seever')
def put_file():
print yellow("Start put configuration file ...")
run("cp -r %s %s_%s.back" % (env.deploy_nginx_conf,env.deploy_nginx_conf,time.strftime("%Y%m%d")))
result = put(env.project_nginx_conf,env.deploy_nginx_conf)
if result.failed and no("put file failed, Continue[Y/N]?"):
abort("Aborting file put task!")
print green("put to configuration files successfully!")
@task
def start():
execute(get_file)
execute(put_file)
|