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. 洛谷1027 Car的旅行路线

    原题链接 将每个城市拆成四个点,即四个机场来看,那么这题就是求最短路. 不过建图有些麻烦,先要找出第四个机场的坐标. 设另外三个机场的坐标为\((x_1, y_1), (x_2, y_2), (x_3 ...

  2. vue项目跳转到外部链接

    vue项目中遇到一个打印的功能.思考之后决定点击按钮,跳转到一个HTML页面(后台写的),利用window.print()方法调用浏览器的打印的功能. 所以,现在的问题是,怎样跳转到外部链接.开发vu ...

  3. oracle service name sid , 用户 和 表空间

    oracle 的四个概念: 数据库: 就是一堆静态的数据文件.注意是静态的 instance 实例: 可以类比数据库连接. 实例就是为了操作数据库而开辟的进程和内存空间,有了这个实例你才能操作数据库. ...

  4. 什么是 superset

    Superset 是 Airbnb 开源的大数据可视化平台,其特性包括: backend 支持几乎所有主流的数据库 支持复杂的权限控制和管理(OpenId, OAuth 等),满足企业内部不同部门人员 ...

  5. k8s 安装步骤

    1 安装Docker 1.1 增加中国区镜像 https://registry.docker-cn.com 2 下载安装k8s的镜像的脚本 https://github.com/AliyunConta ...

  6. AndroidStudio 问题点 - app:preFUNDebugAndroidTestBuild

    Error:Execution failed for task ':app:preFUNDebugAndroidTestBuild'. >Conflictwith dependency 'com ...

  7. c语言基础课第一次作业

    1)大学和高中最大的不同是没有人天天看着你,请看大学理想的师生关系是?有何感想? 通过阅读邹欣老师的博客,了解到了老师心中理想的师生关系是(健身教练与健身学员).在初中,高中我们一直都是填鸭式教育,像 ...

  8. tensorflow学习之(十)使用卷积神经网络(CNN)分类手写数字0-9

    #卷积神经网络cnn import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_data #数据包,如 ...

  9. license

    http://139.199.89.239:1008/4571ab86-eb0d-4d2b-999e-37406bb8ba38 _~~~ rO0ABXNyAChjb20uemVyb3R1cm5hcm9 ...

  10. 人工智能&物联网开发的目录

    走进嵌入式开发的世界,企业级项目课程让你达到企业嵌入式应用开发要求.名师在线答疑,解决疑难.科学评测体系,系统评估学习.核心项目实........ 30 门课程 241小时12分钟 824 人学习 学 ...