fabric - 如何让某些 Fabric 任务仅在本地运行一次,而其他任务则在所有主机上运行

标签 fabric continuous-delivery autodeploy

在我的结构脚本中,我遇到以下问题。我有一个主要任务称为自动部署。在此任务中,我有一些只想在本地运行一次的任务。所有远程任务都应在主机列表中的每个主机上运行。

env.roledefs ={
  'testing': ['t-server-01', 't-server-02']  
  'staging': ['s-server-01', 's-server-02']  
  'live': ['l-server-01', 'l-server-02']  
}

def localtask1():
  # download artifact

def localtask2(): 
  # cleanup locally

def remotetask():
  # deploy artifact to all hosts

def autodeploy():
  localtask1() # run this task only once, locally  

  remotetask() # run this task on all hosts

  localtask2() # run this task only once

调用如下。我想将角色作为属性传递。

fab -R test autodeploy

最佳答案

使用包装函数 autodeploy 中的执行函数,并为远程任务指定主机列表。

对于另外两个,您可以使用execute调用它们,就像远程任务一样,或者直接调用它们。使用它们内部的本地函数就可以了,不需要在本地主机上使用 ssh。

文档是 here如何最好地使用新的execute function .

编辑

既然您在评论中提到了不同的用例,我将根据已经给出的文档中的位来模拟您的做法,添加 param passing section

代码:

#copy above

#redefine this one
def autodeploy(role_from_arg):
    localtask1()
    execute(remotetask, role=role_from_arg)
    localtask2()

#calls like fab autodeploy:testing

关于fabric - 如何让某些 Fabric 任务仅在本地运行一次,而其他任务则在所有主机上运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12492405/

相关文章:

ibm-cloud - 我的一项 IBM Cloud Continuous Delivery 管道作业停止工作。管道中有什么变化吗?

java - 使用intellij时如何在vertx中启用自动重新部署

java - Vertx自动化部署

python Fabric : How to handle arbitrary remote shell prompt for input?

python - Fabric :如何双隧道

python - 手动安装 python 依赖项不起作用。为什么?

database - 持续部署和数据库

maven - 如何在非标准 maven reactor 构建中设置版本?

PHP:通过 HTTP 和命令行运行脚本时的结果不同

python - 是否可以部署使用 Python 3.4 和 Fabric 的应用程序?