简体   繁体   English

如何在Fabric中以并行模式运行命令?

[英]How can I run a command once in parallel mode in fabric?

I have a fabric script to manage our deployments. 我有一个fabric脚本来管理我们的部署。 I need it to run in parallel mode so it can finish in a reasonable amount of time, but I need one command to run only once, not multiple times as it would in parallel mode. 我需要它以并行模式运行,因此它可以在合理的时间内完成,但是我需要一个命令只运行一次,而不是像并行模式那样多次运行。

Don't specify the hosts before executing the function which you would like to execute only one time. 在执行您只想执行一次的功能之前,请不要指定主机。 After that function, you can set env.host variable to the machines you want to run on. 在该函数之后,您可以将env.host变量设置为要运行的计算机。 For example, 例如,

def task():
    init()
    execute(main_job)

def init():
    # do some initialization

    # set host
    env.host = ['192.168.5.11', '192.168.5.12']

@parallel
def main_job():
    # main job code...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM