gpt4 book ai didi

python - 在装饰器中调用具有较少主机的结构嵌套方法

转载 作者:太空宇宙 更新时间:2023-11-03 18:55:32 36 4
gpt4 key购买 nike

我有

@roles('production')
def submethod():
run('service restart')


@roles('all')
def deploy():
put('somefile.conf')
submethod()

我调用了deploy(),但随后所有主机中的所有服务都重新启动,完成此操作的最佳方法是什么?看来@roles('生产') 不起作用......

非常感谢。

最佳答案

如果你想从另一个任务调用一个任务,你应该使用 execute :

def submethod():
run('service restart')


@roles('all')
def deploy():
put('somefile.conf')
execute(submethod, roles=['production'])

希望有帮助。

关于python - 在装饰器中调用具有较少主机的结构嵌套方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17349388/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com