官网地址

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. 使用fdisk进行磁盘管理

    http://itercast.com/lecture/17 disk是来自IBM的老牌分区软件,几乎所有Linux系统均默认安装 fdisk是一个MBR分区工具,不可用于GPT分区 只有超级用户(r ...

  2. Word Ladder 解答

    Question Given two words (beginWord and endWord), and a dictionary's word list, find the length of s ...

  3. HBase 4、Phoenix安装和Squirrel安装

    描述 现有hbase的查询工具有很多如:Hive,Tez,Impala,Shark/Spark,Phoenix等.今天主要记录Phoenix. phoenix,中文译为“凤凰”,很美的名字.Phoen ...

  4. Unity NGUI 血条制作

    NGUI 血条制作步骤 实现过程: 模拟血条的变化当点击按钮Button是血条会实时发生变化. 1.向Unity中导入NGUI2.6.3.unitypackage 点击create your ui 后 ...

  5. MySQL中explain的type类型

    |  ALL              |  全表扫描 |  index            |  索引全扫描 |  range            |  索引范围扫描,常用语<,<= ...

  6. jar包和war包的区别:

    jar包就是别人已经写好的一些类,然后将这些类进行打包,你可以将这些jar包引入你的项目中,然后就可以直接使用这些jar包中的类和属性了,这些jar包一般都会放在lib目录下.  war是一个web模 ...

  7. PHP学习笔记1.1——date()函数的多种用法,取出各种不同格式的时间,非常全面

    语法格式:date(string format.int timestamp); 参数一:format指定输出的日期和时间的格式,具体的参见下表; 参数二:timestamp是可选参数,是时间戳,如果不 ...

  8. (原)前端知识杂烩(css系列)

    更新于 20160217 1. css hack .pad{ padding:17px 0 0 17px; /* 普通写法 */ *padding:17px 0 0 17px; /* *为IE7 *+ ...

  9. javascript动态创建对象

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  10. /boot磁盘空间不足,没盘扩展,只好删除旧内核了

    [xiejdm@localhost ~]$ uname -r -.el7.x86_64 [xiejdm@localhost ~]$ sudo rpm -qa | grep kernel kernel- ...