python - Fabric - 通过执行将参数传递给任务

标签 python fabric

我有以下 Fabric 任务:

def ssh_keygen(user, dir):
   env.user = user
   run("ssh-keygen  %s" % dir)

我想使用“执行”来调用它,但需要向任务传递一个参数。即用户和目录

execute(ssh_keygen('jbloggs', '/home/jbloggs'), hosts=["server1"])

但是这不起作用:

No hosts found. Please specify (single) host string for connection: Traceback (most recent 

有什么办法可以实现吗?

最佳答案

execute(ssh_keygen, 'jbloggs', '/home/jbloggs', host="server1")

关于python - Fabric - 通过执行将参数传递给任务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22709799/

相关文章:

python - kill linux 命令执行后结构进程中断

python - 测试需要用户输入的 Python 函数()

python - Sublime Text : Hide all code and show only comments (with line break)

python - 乘以上面的单元格以使用公式创建 pandas 数据框

python - 通过 dict 变量到 stat 模块的路径

Python fabric "local"函数不遵守环境变量 DJANGO_SETTINGS_MODULE

python - 可以用正则表达式匹配字符重复吗?如何?

django - 在本地运行结构脚本

python - 将 Fabric 命令的输出保存在列表中,其中每一行都是一个列表元素

python - 结构差异 sudo() run ('sudo cmd' )