1 - Fabric

Fabric是一个Python的库,提供了丰富的同SSH交互的接口,可以用来在本地或远程机器上自动化、流水化地执行Shell命令。

非常适合用来做应用的远程部署及系统维护。简单易用,只需懂得基本的Shell命令。

2 - 版本区分

目前,从PyPI可以搜索到主要的fabric库为“ Fabric 2.1.3 ”、“ fabric2 2.1.3 ”和“ Fabric3 1.14.post1 ”。

  • Fabric:官方Fabric,兼容 Python 2 & Python 3,但不兼容Fabric 1.x的fabfile;
  • fabric2: 与Fabric相同,仅作为平滑迁移(使用Fabric包安装1.x 版本,使用Fabric2包安装2.x版本,来实现1.x和2.x的共存);
  • Fabric3:是一个基于Fabric 1.x 的fork,兼容Python2 & Python3,兼容 Fabric1.x 的 fabfile;

 
Fabric 1.x 与2.x版本的主要区别:
  • Fabric 1.x只支持Python2.5-2.7,而Fabric2支持Python (2.7, 3.4+);
  • Fabric 2.x是重写Fabric 1.x的版本,不再兼容1.x 版本的fabfile,而且有些模块和用法也发生了很大改变;
  • 具体信息请见:Rewrite for 2.0! See Upgrading from Fabric 1.x

3 - 关于Fabric3

Fabric3 is a Python (2.7 or 3.4+) library and command-line tool for streamlining the use of SSH for application deployment or systems administration tasks.
This is a fork of the original Fabric (git) with the intention of providing support for Python3, while maintaining support for all non-archaic versions of Python2.
 
 
注意
  • 当前版本“Fabric3 1.14.post1”的功能和使用方法仍然与“Fabric 1.x.”基本一致。
  • 安装fabric3之前,需要先卸载fabric。
 $ pip2 uninstall fabric
$ pip2 install fabric3 --proxy="10.144.1.10:8080" $ pip2 show fabric3
Name: Fabric3
Version: 1.14.post1
Summary: Fabric is a simple, Pythonic tool for remote execution and deployment (py2./py3.+ compatible fork).
Home-page: https://github.com/mathiasertl/fabric/
Author: Mathias Ertl
Author-email: mati@er.tl
License: UNKNOWN
Location: c:\python27\lib\site-packages
Requires: paramiko, six
Required-by:

4 - 问题处理

1 - 导入fabric.api提示报错“No module named api”
 >>> from fabric.api import run
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named api
>>>

处理方法:

  确认fabric版本信息,“from fabric.api import run”的方式只适用fabric1.x版本。

2 - 运行fabric示例提示报错“No idea what 'hello' is!”

 $ cat fabfile.py
# coding:utf-8 def hello():
print("hello fabric!") $ fab hello
No idea what 'hello' is! $ fab --list
No tasks found in collection 'fabfile'!
处理方法:
  确认fabric版本信息,fabric2.x版本不兼容Fabric 1.x的fabfile。遵照fabric 2.x要求,更改fabfile文件内容格式,重新运行即可。
 $ pip show fabric
Name: fabric
Version: 2.1.3
Summary: High level SSH command execution
Home-page: http://fabfile.org
Author: Jeff Forcier
Author-email: jeff@bitprophet.org
License: BSD
Location: c:\python27\lib\site-packages
Requires: paramiko, invoke, cryptography
Required-by: $ cat fabfile.py
from invoke import task @task
def hello(c):
c.run("echo 'hello fabric'")
print("hello fabric!") $ $ fab --list
Available tasks: hello $ fab hello
'hello fabric'
hello fabric! $

5 - 参考信息

以下内容主要适用于Fabric 1.x 和 Fabric3。

Python - Fabric简介的更多相关文章

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

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

  2. Python Fabric ssh 配置解读

    Python Fabric ssh 配置解读 Fabric 2.4简介: Fabric is a high level Python (2.7, 3.4+) library designed to e ...

  3. 使用python fabric搭建RHEL 7.2大数据基础环境以及部分优化

    1.使用python fabric进行Linux基础配置 使用python,可以让任何事情高效起来,包括运维工作,fabric正式这样一套基于python2的类库,它执行本地或远程shell命令提供了 ...

  4. Python的简介以及安装和第一个程序以及用法

    Python的简介: 1.Python是一种解释型.面向对象.动态数据类型的高级程序设计语言.自从20世纪90年代初Python语言诞生至今,它逐渐被广泛应用于处理系统管理任务和Web编程.Pytho ...

  5. [Python] heapq简介

    [Python] heapq简介 « Lonely Coder [Python] heapq简介 judezhan 发布于 2012 年 8 月 8 日 暂无评论 发表评论 假设你需要维护一个列表,这 ...

  6. Python Fabric模块详解

    Python Fabric模块详解 什么是Fabric? 简单介绍一下: ​ Fabric是一个Python的库和命令行工具,用来提高基于SSH的应用部署和系统管理效率. 再具体点介绍一下,Fabri ...

  7. python fabric安装

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

  8. 后端程序员之路 6、Python fabric

    直接写shell固然也很好,但是用python来写脚本,也是美滋滋.fabric是一个封装部署.多机操作等功能的python库. Welcome to Fabric! - Fabric documen ...

  9. Python单元测试简介及Django中的单元测试

    Python单元测试简介及Django中的单元测试 单元测试负责对最小的软件设计单元(模块)进行验证,unittest是Python自带的单元测试框架. 单元测试与功能测试都是日常开发中必不可少的部分 ...

随机推荐

  1. python 10 迭代器和三元运算符

    一.迭代器 1.迭代器协议:对象必须提供一种next方法,执行该方法要么返回迭代中的下一项,要么引起一个stopIteration异常,终止迭代 2.可迭代对象:实现了迭代器协议的对象 3.pytho ...

  2. C# WPF 父控件通过使用可视化树找到子控件

    在我们使用WPF设计前台界面时,经常会重写数据模板,或者把控件放到数据模板里.但是一旦将控件放到数据模板中,在后台就没有办法通过控件的名字来获取它了,更没办法对它进行操作(例如,隐藏,改变控件的某个值 ...

  3. Mac 安装配置Jenkins+github完成项目构建

    Jenkins Jenkins是一款开源 CI&CD 软件,用于自动化各种任务,包括构建.测试和部署软件.Jenkins 支持各种运行方式,可通过系统包, Docker 或者通过一个独立的 J ...

  4. KVM 虚拟机的热迁移

    热迁移:顾名思义在虚拟机不关机的情况下将KVM虚拟机进行迁移 准备工作:两台KVM虚拟机,一台nfs虚拟机,centos7.4系统 主机 IP地址 主机名 KVM01 10.00.11 kvm01 K ...

  5. 每日一练ACM 2019.04.14

    2019.4.14 第1001题:Sum Problem Problem DescriptionHey, welcome to HDOJ(Hangzhou Dianzi University Onli ...

  6. PHP PDO预定义常量

    以下常量由本扩展模块定义,因此只有在本扩展的模块被编译到PHP中,或者在运行时被动态加载后才有效. 注意: PDO使用类常量自PHP 5.1.以前的版本使用的全局常量形式PDO_PARAM_BOOL中 ...

  7. PHP引用(&)练习

    <?php class talker { private $data = 'Hi'; public function & get(){ //返回值指向一个内容,这里是指向$data的内容 ...

  8. java面试一、1.1基础

    免责声明:     本文内容多来自网络文章,转载为个人收藏,分享知识,如有侵权,请联系博主进行删除. 基础篇 1.1Java基础 面向对象的特征:继承.封装和多态 三大特性是:封装,继承,多态 所谓封 ...

  9. war包远程部署访问不到问题解决过程总结

    项目完成后,先在本地ide测,用ide集成的tomcat,顺理发布,访问,然后放本地tomcat的webapp文件夹,顺理启动,访问,再放远程阿里云的tomcat的webapp文件夹,重启tomcat ...

  10. 基于SVG.js实现网页初始化线条描绘效果

    前端实现看到一个网页的效果很cool(参考https://tympanus.net/Development/SVGDrawingAnimation/index2.html),决定自己去实现以下这个效果 ...