官网地址

1.安装

 pip install fabric

依赖 Paramiko 、PyCrypto库

  以下依赖肯能要手动安装 

#安装 pycrypto 密码库
pip install pycrypto

#安装 pycrypto 依赖
pip install ecdsa

ps:【windows7 x64 ,python2.7 】Windows下pip安装包报错:Microsoft Visual C++ 9.0 is required Unable to find vcvarsall.bat   
   
    可以安装一个Micorsoft Visual C++ Compiler for Python 2.7的包

2.fabric使用

新建py脚本:fabfile.py

 def hello():
print("Hello world!")

执行fab命令

fab hello

如果当前模块下没有fabfile.py文件,那么需要指定-f参数

 fab -f test.py hello

使用参数

def hello(name, value):
print("%s = %s!" % (name, value)) fab hello:name=age,value=20

执行本地操作

from fabric.api import local, lcd

def lsfab():
  with lcd('~/tmp/fab'):
  local('ls')

远程操作

def setting_ci():
local('echo "add and commit settings in local"') def update_setting_remote():
print "remote update"
with cd('~/temp'): #cd用于进入某个目录
run('ls -l | wc -l') #远程操作用run

多服务器操作

#!/usr/bin/env python
# encoding: utf-8 from fabric.api import *
env.roledefs = {
'testserver': ['user1@host1:port1',],
'productserver': ['user2@host2:port2', ]
} @roles('testserver')
def task1():
run('ls -l | wc -l') @roles('productserver')
def task2():
run('ls ~/temp/ | wc -l') def do():
execute(task1)
execute(task2)

用不同颜色打印

from fabric.colors import *

def show():
print green('success')
print red('fail')
print yellow('yellow')

fabric 命令行工具

装饰器作用?
@task
@parallel 命令行常用: fab --help
fab -l -- 显示可用的task(命令)
fab -H -- 指定host,支持多host逗号分开
fab -R -- 指定role,支持多个
fab -P -- 并发数,默认是串行
fab -w -- warn_only,默认是碰到异常直接abort退出
fab -f -- 指定入口文件,fab默认入口文件是:fabfile/fabfile.py

 更多参见官网

   

fabric 安装及使用的更多相关文章

  1. MySQL:Fabric 安装

    MySQL Fabric安装 MySQL Fabric是Oracle提供的用于辅助进行ha\sharding的工具,它的基本架构: 从上面看出,借助于Fabric, 可以搭建 HA 集群.Sharin ...

  2. 002_HyperLedger Fabric安装部署

    上一次我们把HyperLedger Fabric的环境全部搭建好了,下面开始正式的HyperLedger Fabric安装部署 首先需要安装编译工具gcc,用命令yum install -y gcc安 ...

  3. fabric 安装

    fabric 是一个python的库,fabric可以通过ssh批量管理服务器. 第一步安装依赖包 安装fabric依赖及pip yum install -y python-pip gcc pytho ...

  4. fabric安装使用

    可以使用pip安装fabric,注意使用pip 安装fabric时,一定要指定版本,不要安装2.0版本的,无论怎样都会提示没有api这样模块,所以指定安装 pip install fabric==1. ...

  5. fabric 安装及简单使用 (centos6)

    fabric 是一个python的库,fabric可以通过ssh批量管理服务器. 第一步安装依赖包 安装epel源 1 wget -O /etc/yum.repos.d/epel.repo http: ...

  6. python fabric安装

    1 安装epel wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo 2 安装pip yum i ...

  7. 安装 python 的 pip install fabric 库 问题

    安装 pip install fabric 安装依赖需要 gcc 并且不能单独的安装gcc 还要安装完整的gcc依赖 yum -y install gcc gcc-c++ kernel-devel y ...

  8. python安装paramiko模块

    一.简介 paramiko是用python语言写的一个模块,遵循SSH2协议,支持以加密和认证的方式,进行远程服务器的连接. 由于使用的是python这样的能够跨平台运行的语言,所以所有python支 ...

  9. Python Fabric远程自动部署简介

    Fabric是一个Python(2.5-2.7)库,用于简化使用SSH的应用程序部署或系统管理任务. 它提供的操作包括:执行本地或远程shell命令,上传/下载文件,以及其他辅助功能,如提示用户输入. ...

随机推荐

  1. cf478B Random Teams

    B. Random Teams time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

  2. UESTC_Palindromic String 2015 UESTC Training for Search Algorithm & String<Problem M>

    M - Palindromic String Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 128000/128000KB (Java ...

  3. C pointers

    指向整型数组指针int (*p)[10] = matrix;增加这个指针的值使它指向下一个整型数组 指向整型指针int *pi = &matrix[0][0];int *pi = &m ...

  4. Mod_python: The Long Story

    mod_python: the long story - Grisha Trubetskoy Mod_python: The Long Story Oct 25th, 2013 | Comments ...

  5. jackson的简单使用(可转xml)

    参考文章:http://www.cnblogs.com/hoojo/archive/2011/04/22/2024628.html  (原文章更详细哦,且有介绍xml与java对象的互转) 参考文章作 ...

  6. cf#366....

    惨惨惨.... 我需要av.. b题意看错想了个加强版博弈结果发现完全没必要= =....cwa12到结束....中途想看d....只会n^4暴力啊.. 题解明天补上

  7. java模拟get/post提交

    1:用jdk连接 String action = "xxxxxxxxxxx": URL url = new URL(action); HttpURLConnection http ...

  8. HTML高级标签(2)————窗体分帧(2)————后台管理页面

    使用frameset进行窗体分帧.构建简易的后台页面.这篇博客就作为一个简易后台管理页面的实战演练. watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvd3px ...

  9. 力挺8天入门wpf【转载】

    8天入门wpf—— 第八天 最后的补充 摘要: 从这一篇往前看,其实wpf中还有很多东西没有讲到,不过我的原则还是将比较常用的知识点过一遍,如果大家熟悉了这些知识,基本功也就打的差不多了,后续可以等待 ...

  10. ubuntu如何开启SSH服务

    ubuntu如何开启SSH服务 分类: Linux 运维与操作基础2013-02-24 13:33 2868人阅读 评论(0) 收藏 举报 sshd ubuntu ubuntu默认并没有安装ssh服务 ...