【python-Fabric:与一个用户连接到计算机,然后对另一个用户进行处理】教程文章相关的互联网学习教程文章

python – Fabric:作为特定用户执行所有操作【代码】

我的构建和生产部署由一个用户特定用户使用密钥连接,该用户在部署期间共享,并在计算机启动期间复制密钥. 这个用户部署,共享ssh密钥,允许ssh到任何prod机器和它们之间. 现在,我的结构构建以用户Jenkins运行. 如何指示Fabric作为特定用户执行所有操作(在这种情况下部署)?相当于sudo su deploy 我不想在每个任务中都使用前缀或前缀.而是设置一个全局变量. jenkins是轮组,有sudo烫发解决方法:如果我正确理解您的问题,您希望以不使用前...

python – Fabric命名空间想要一个fabfile【代码】

我正在完成Fabric Namespaces的基础教程. 我希望做类似于Structuring a fabric project with namespaces的事情 我的__init__.py文件看起来:from fabric.api import task@task def abc():pass当我运行fab –list时,我收到此错误:me@galvatron:/tmp/fabric_test$fab --listFatal error: Couldn't find any fabfiles!Remember that -f can be used to specify fabfile path, and use -h for help.Aborting.谁能告诉我我错过了什么或...

python – 为什么Fabric使用/ bin / sh【代码】

我试图在远程服务器上运行一些命令.我需要在那里获取一些bash文件.不幸的是,似乎结构(突然,最近?)开始使用/ bin / sh,并且因为我在脚本中使用bash语法而中断了.我找到了this:If shell is True (the default), run will execute the given command string via a shell interpreter, the value of which may be controlled by setting env.shell (defaulting to something similar to /bin/bash -l -c “”.) Any double-quote (“...

Python编程:fabric实现SSH链接管理服务器【代码】

fabric 可以很轻松的实现 SSH链接 安装 pip install fabric查看版本 $ fab --version Fabric 2.4.0 Paramiko 2.4.1 Invoke 1.2.0编写任务 fabfile.py # -*- coding: utf-8 -*-from fabric import task, Connection@task def local_list(ctx):# 执行本机命令ctx.run("ls")@task def remote_list(ctx):# 链接远程服务器执行命令 conn = Connection("root@big-doc")conn.run("ls")conn.close() 运行任务 $ fab -l Available tasks:loc...

使用fabric远程部署fail2ban-python【代码】

使用fabric远程部署fail2ban-python 脚本示例 # -*- coding:utf-8 -*- from fabric.api import *env.hosts = ['主机ip'] env.port = 50022 env.user = 'root' env.password = '用户密码'@task def install_fail2ban():sudo('apt-get update')sudo('apt-get upgrade')sudo('apt-get install fail2ban -y')sudo('systemctl start fail2ban')sudo('systemctl enable fail2ban')put(remote_path='/etc/fail2ban/jail.local', local_pat...

python三大神器之fabric(2.0新特性)【代码】

fabric经常出现在自动化运维领域,批量处理一些运维工作。fabric是在paramiko之上又封装了一层,操作起来更加简单易用。 本来只是想写个博客记录一下,然后发现之前写的代码不能运行了,报以下错误:No module named fabric.apiTraceback (most recent call last):File "D:/PycharmProjects/TestTool/Publish/fabric_sample.py", line 3, in <module>from fabric.api import * ModuleNotFoundError: No module named fabric.api ...

python fabric 编写SSH 连接类

#-*- coding:utf8 -*- from fabric import Connectionclass linuxOper(object): def __init__(self,ipaddr,user=root,password=,port=22,gateway=): self.gateway = gateway if self.gateway: self.connobj = Connection(host=ipaddr, user=user,connect_kwargs={password:password},port=int(port),gateway=self.gateway,) else: self.co...

Python-Fabric将停止Redis服务器,但不会再次启动它【代码】

Fabric将停止我的Redis服务器,但不会启动.我尝试使用面料,但使用paramiko却奏效了.为什么Fabric无法启动Redis服务器?我可以使用paramiko,但这似乎有些不妥.[ec2-xxx-xxx-xxx.compute-1.amazonaws.com] Executing task 'redis_master_role' [master.redis.htdevops.com] Executing task 'redis_master_stop' [master.redis.htdevops.com] sudo: service redis_6379 stop [master.redis.htdevops.com] out: Stopping ... [master.re...

在Windows上安装Fabric(Python库)时出现“错误:找不到vcvarsall.bat”

这个问题已经在这里有了答案: > error: Unable to find vcvarsall.bat 41个我尝试在Windows 7 64位计算机上安装Fabric,而我得到的只是这个糟糕的错误消息:building ‘Crypto.Random.OSRNG.winrandom’ extension warning: GMP or MPIR library not found; Not buildingCrypto.PublicKey._fastmath. error: Unable to find vcvarsall.bat没有类似问题的答案:Unable to...

python – 获取使用fabric run命令启动的进程的PID【代码】

如何获取fabric run命令启动的进程的PID.我想跟踪PID,以防我想要杀死进程.有没有更好的方法来处理这种情况?解决方法:这应该有效,因为运行命令打开的shell在运行命令的echo部分时仍然打开:run("mycommand & echo $!")