Can a Python Fabric task invoke other tasks and respect their hosts lists?

后端 未结 4 1153
误落风尘
误落风尘 2020-12-30 20:52

I have a fabfile like the following:

@hosts(\'host1\')
def host1_deploy():
    \"\"\"Some logic that is specific to deploying to host1\"\"\"

@hosts(\'host2\         


        
4条回答
  •  Happy的楠姐
    2020-12-30 21:06

    There's probably a better way to handle it, but you could pass both hosts to deploy(), and then in host1_deploy() and host2_deploy() check env.host:

    def host1_deploy():
        if env.host in ['host1']:
             run(whatever1)
    
    def host2_deploy():
        if env.host in ['host2']:
             run(whatever2)
    
    @hosts('host1','host2')
    def deploy():
        host1_deploy()
        host2_deploy()
    

提交回复
热议问题