标签:标记 常用 显示 apt bootstra 装饰器 cal host log
【Fabric】
Fabric是一个用Python开发的部署工具,最大特点是不用登录远程服务器,在本地运行远程命令,几行Python脚本就可以轻松部署。
安装
wget https://bootstrap.pypa.io/get-pip.py python get-pip.py pip install fabric
from fabric.api import * env.user = ‘mysql‘ env.hosts = [‘192.168.56.1‘, ‘192.168.56.2‘] #env.password = ‘1qaz@WSX‘ env.passwords = { ‘root@192.168.56.1:22‘:‘1qaz@WSX‘, ‘root@192.168.56.2:22‘:‘1qaz@WSX‘, } @task @runs_once def tar_task(): with lcd(‘/home/mysql/yanjun_wang‘): local(‘tar zcvf hello.tar.gz hello_world.py‘) @task def put_task(): run(‘mkdir -p /home/mysql/yanjun_wang‘) with cd(‘/home/mysql/yanjun_wang‘): put(‘/home/mysql/yanjun_wang/hello.tar.gz‘, ‘/home/mysql/yanjun_wang/hello.tar.gz‘) @task def check_task(): lmd5 = local(‘md5sum /home/mysql/yanjun_wang/hello.tar.gz‘, capture=True).split(‘ ‘)[0] rmd5 = run(‘md5sum /home/mysql/yanjun_wang/hello.tar.gz‘).split(‘ ‘)[0] if lmd5 == rmd5: print(‘OK ...‘) else: print(‘ERROR ...‘) @task def run_task(): with cd(‘/home/mysql/yanjun_wang‘): run(‘tar zxvf hello.tar.gz‘) run(‘python hello_world.py‘) @task def execute(): print(‘start ...‘) tar_task() put_task() check_task() run_task() print(‘end ...‘)
标签:标记 常用 显示 apt bootstra 装饰器 cal host log
原文地址:http://www.cnblogs.com/vadim/p/7532411.html