栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

fabric的使用(python)

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

fabric的使用(python)

fabric 强大的运维工具包,python 实现自动化部署。

建立连接

from fabric import Connection
c = Connection(host=host,user=user,connect_kwargs={"password":"ubuntu")

执行shell 命令

c.run("uname -a")
c.sudo("ls",password="")

切换目录

with c.cd("../"):
	c.run("pwd")
实用小例:
def upload_and_unpack(c):
	"""上传解压"""
    c.put("fabric_01.zip", "/home/ubuntu/")
    c.run('unzip -o /home/ubuntu/fabric_01.zip -d /home/ubuntu/data')
    c.run("ls")
    with c.cd("/home/ubuntu/data"):
        res = c.run("ls")
        print("======")
        print(res.stdout)
        print(res.exited)
def pack_and_download(c):
	"""打包下载"""
    "zip -r test.zip /home/ubuntu/"
    c.run("ls") # 打包
    c.run("pwd")
    c.run("zip -r test.zip /home/ubuntu/test")
    with c.cd("/home/ubuntu"):
        c.get("test.zip", r"D:\")

参考:[https://docs.fabfile.org/en/2.6/getting-started.html]

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/747089.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号