pythonfabric在多台计算机上运行命令

2024-05-15 00:16:39 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用pythonfabric在多个主机上并行执行命令。在

我有以下场景。在

def list1():
  env.hosts=[H1,H2,H3]
def myfunction():
   #login into H1 and execute a command and wait for certain string.
   #once get the string login to H2 and H3 in parallel and execute some other command

现在我必须在H1上运行一个命令,当我从H1输出中得到一些想要的字符串时,我需要在H2和H3上运行其他命令。 都是linux机器。在

跑步

^{pr2}$

像这样是不对的。我有什么办法可以做到这一点吗?在

谢谢


Tags: and命令envexecutestringdef场景login
1条回答
网友
1楼 · 发布于 2024-05-15 00:16:39

我不知道我是否明白你想要什么。我假设您希望在h1上运行一个任务,等待结果并将此结果用作h2和h3上的任务的输入。如果你想回答其他问题,请忘记回答

一种选择是创建一个执行fab任务的python脚本(而不是fab文件)。在

比如:

import fabfile    
from fabric.tasks import execute

result = execute(fabfile.command_for_h1, hosts=[h1])
result_h1 = result[h1]
execute( fabfile.command_for_h2_h3, hosts=[h2,h3], result_h1 )

关键是execute方法。在

相关问题 更多 >

    热门问题