How to set target hosts in Fabric file

后端 未结 15 790
南方客
南方客 2020-11-29 15:27

I want to use Fabric to deploy my web app code to development, staging and production servers. My fabfile:

def deploy_2_dev():
  deploy(\'dev\')

def deploy_         


        
15条回答
  •  臣服心动
    2020-11-29 16:03

    Was stuck on this myself, but finally figured it out. You simply can't set the env.hosts configuration from within a task. Each task is executed N times, once for each Host specified, so the setting is fundamentally outside of task scope.

    Looking at your code above, you could simply do this:

    @hosts('dev')
    def deploy_dev():
        deploy()
    
    @hosts('staging')
    def deploy_staging():
        deploy()
    
    def deploy():
        # do stuff...
    

    Which seems like it would do what you're intending.

    Or you can write some custom code in the global scope that parses the arguments manually, and sets env.hosts before your task function is defined. For a few reasons, that's actually how I've set mine up.

提交回复
热议问题