Python - Fabric简介
1 - Fabric
Fabric是一个Python的库,提供了丰富的同SSH交互的接口,可以用来在本地或远程机器上自动化、流水化地执行Shell命令。
非常适合用来做应用的远程部署及系统维护。简单易用,只需懂得基本的Shell命令。
- HomePage:http://www.fabfile.org/
- Docs:http://docs.fabfile.org/
- GitHub:https://github.com/fabric/fabric/
- ChangeLog:http://www.fabfile.org/changelog.html
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只支持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 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 - 问题处理
>>> 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'!
$ 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 - 参考信息
- [Python远程部署利器Fabric详解](http://python.jobbole.com/87241/)
- [fabric实现远程操作和部署](http://python.jobbole.com/83716/)
- 中文文档:http://fabric-chs.readthedocs.io/zh_CN/chs/
- [Python模块学习 - fabric](https://www.cnblogs.com/xiao-apple36/p/9124292.html)
Python - Fabric简介的更多相关文章
- Python Fabric远程自动部署简介
Fabric是一个Python(2.5-2.7)库,用于简化使用SSH的应用程序部署或系统管理任务. 它提供的操作包括:执行本地或远程shell命令,上传/下载文件,以及其他辅助功能,如提示用户输入. ...
- Python Fabric ssh 配置解读
Python Fabric ssh 配置解读 Fabric 2.4简介: Fabric is a high level Python (2.7, 3.4+) library designed to e ...
- 使用python fabric搭建RHEL 7.2大数据基础环境以及部分优化
1.使用python fabric进行Linux基础配置 使用python,可以让任何事情高效起来,包括运维工作,fabric正式这样一套基于python2的类库,它执行本地或远程shell命令提供了 ...
- Python的简介以及安装和第一个程序以及用法
Python的简介: 1.Python是一种解释型.面向对象.动态数据类型的高级程序设计语言.自从20世纪90年代初Python语言诞生至今,它逐渐被广泛应用于处理系统管理任务和Web编程.Pytho ...
- [Python] heapq简介
[Python] heapq简介 « Lonely Coder [Python] heapq简介 judezhan 发布于 2012 年 8 月 8 日 暂无评论 发表评论 假设你需要维护一个列表,这 ...
- Python Fabric模块详解
Python Fabric模块详解 什么是Fabric? 简单介绍一下: Fabric是一个Python的库和命令行工具,用来提高基于SSH的应用部署和系统管理效率. 再具体点介绍一下,Fabri ...
- python fabric安装
1 安装epel wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo 2 安装pip yum i ...
- 后端程序员之路 6、Python fabric
直接写shell固然也很好,但是用python来写脚本,也是美滋滋.fabric是一个封装部署.多机操作等功能的python库. Welcome to Fabric! - Fabric documen ...
- Python单元测试简介及Django中的单元测试
Python单元测试简介及Django中的单元测试 单元测试负责对最小的软件设计单元(模块)进行验证,unittest是Python自带的单元测试框架. 单元测试与功能测试都是日常开发中必不可少的部分 ...
随机推荐
- 优美序列(sequence)
问题描述 Lxy养了N头奶牛,他把N头奶牛用1..N编号,第i头奶牛编号为i.为了让奶牛多产奶,每天早上他都会让奶牛们排成一排做早操.奶牛们是随机排列的.在奶牛排列中,如果一段区间[L,R]中的数从小 ...
- HDU 2196.Computer 树形dp 树的直径
Computer Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
- Oracle启动和停止
概述 只有具备sysdba和sysoper系统特权的用户才能启动和关闭数据库. 在启动数据库之前应该启动监听程序,否则就不能利用命令方式来管理数据库,包括启动和关闭数据库. 虽然数据库正常运行,但如果 ...
- Java中的4个并发工具类 CountDownLatch CyclicBarrier Semaphore Exchanger
在 java.util.concurrent 包中提供了 4 个有用的并发工具类 CountDownLatch 允许一个或多个线程等待其他线程完成操作,课题点 Thread 类的 join() 方法 ...
- c语言知识
1. 指针 https://blog.csdn.net/lwbeyond/article/details/6180640 http://www.cnblogs.com/lvyahui/p/696528 ...
- node vue 项目部署问题汇总
场景:vue-router为history模式,不带项目名访问的部署,如果资源是用相对路径加载,则资源匹配路径不对 一.带项目名称访问,如部署到tomcat服务上 webpack: build/ut ...
- Redis学习笔记:与SpringBoot结合使用
首先需要在pom文件中导入相应的Redis依赖(版本可以会变化,下面坐标也可能会变化) <dependency> <groupId>org.springframework.bo ...
- 关于微信小程序切换获取不到元素的问题
1.由于公司要实现微信小程序的自动化,所以开始学习python + appium 实现微信小程序自动化.在学习过程中遇到在切换webview后获取不到页面元素的问题,导致无法继续.今天在网上看到一篇关 ...
- MySQL语法大全_自己整理的学习笔记(MySQL语句 整理二)
select * from emp; #注释 #--------------------------- #----命令行连接MySql--------- #启动mysql服务器 net start m ...
- PID25 / 合并果子 ☆
这里用到了STL里面的priority_queue,我也不是很精通基本上属于现学现卖阶段,http://www.cnblogs.com/flyoung2008/articles/2136485.htm ...