python - 使用 Python Fabric Library 获取 env.hosts 列表的当前值

标签 python fabric

我有这段代码(foobar 是本地服务器):

env.hosts = ['foo', 'bar']

def mytask():
    print(env.hosts[0])

当然,每次迭代都会打印 foo

您可能知道,Fabric 遍历 env.hosts 列表并以这种方式在每个列表上执行 mytask():

fab mytask

taskfoo
上执行 taskbar

上执行

我正在寻找一种在每次迭代中获取当前主机的方法。

谢谢,

最佳答案

使用 env.host_string。您可以找到 env 变量的完整列表 here .

关于python - 使用 Python Fabric Library 获取 env.hosts 列表的当前值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3334936/

相关文章:

python - 初始化dask系列

python - 取最小值和最大值为空值 - pandas groupby

database - Django 部署 : Handling data in database

git - 在部署期间将 git 修订号插入文件

python - 海湾合作委员会错误 : command 'gcc-4.0' failed with exit status 1

python - 元组元素在列表中的位置

python - 使用 Python 进行 requests.get() 后 PDF 文件损坏

python - 从后台 python 进程捕获和使用输入事件,而不通知焦点窗口

python - 如何使用 Fabric 使用 nohup 启动后台进程?

python - 尝试将字典中的值分配给结构环境设置