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自带的单元测试框架. 单元测试与功能测试都是日常开发中必不可少的部分 ...
随机推荐
- node.js 调试 eggs launch.json配置信息
{ // 使用 IntelliSense 了解相关属性. // 悬停以查看现有属性的描述. // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linki ...
- 01-SpringMVC 原理
说明:所有代码调式的环境:开发环境idea,jdk7,tomcat8.5.27,数据库MySQL5.1,spring3.2 SpringMVC 1.什么是SpringMVC? springmvc是sp ...
- [Hadoop]Hadoop章3 NameNode的ZKFC机制
基本概念 首先我们要明确ZKFC 是什么,有什么作用: zkfc是什么? ZooKeeperFailoverController 它是什么?是Hadoop中通过ZK实现FC功能的一个实用工具. 主要作 ...
- 快速实现抖音的分享&登录(android)
快速实现抖音分享与第三方登录 准备工作 1.注册抖音的key到抖音开放平台,点击这里查看步骤: 2.集成ShareSDK到Mob官网文档页面查看即可,点击这里查看集成: 业务代码 分享要求: 视频: ...
- left join中where与on的区别
举例进行说明,我们现在有两个表,即商品表(products)与sales_detail(销售记录表).我们主要是通过这两个表来对MySQL关联left join 条件on与where 条件的不同之处进 ...
- AX_RecordSortedList
static void RecordSortedList(Args _args) { SalesLine localSalesLine,fetchSalesLine; RecordSortedList ...
- 在struts.xml中配置默认action遇到的问题
初始代码: <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC & ...
- nacos 使用记
本文记录SpringBoot和SpringCloud与Nacos作为配置中心的整合过程及问题 Nacos官方使用文档:https://nacos.io/zh-cn/docs/what-is-nacos ...
- JAVA 8 主要新特性 ----------------(七)新时间日期 API -----Instant 时间戳
一.简介 用于“时间戳”的运算.它是以Unix元年(传统 的设定为UTC时区1970年1月1日午夜时分)开始 所经历的描述进行运算 二.文档介绍 1.now Instant instantNow = ...
- 第一次OO总结
作业1——多项式加减法 看到这个名字就开始瑟瑟发抖了,毕竟一年前用C语言让我写这么一个程序都很头疼,什么堆栈啊还有结构都稀里糊涂的,更别说用一个完全没接触过的语言来完成最简单的一次作业.像我这样越老心 ...