Does python fabric support dynamic set env.hosts?

前端 未结 3 1369
误落风尘
误落风尘 2021-02-04 01:41

I want to change the env.hosts dynamically because sometimes I want to deploy to one machine first, check if ok then deploy to many machines. Currently I need to set env.hosts f

3条回答
  •  自闭症患者
    2021-02-04 02:18

    Yes you can set env.hosts dynamically. One common pattern we use is:

    from fabric.api import env
    
    def staging():
        env.hosts = ['XXX.XXX.XXX.XXX', ]
    
    def production():
        env.hosts = ['YYY.YYY.YYY.YYY', 'ZZZ.ZZZ.ZZZ.ZZZ', ]
    
    def deploy():
       # Do something...
    

    You would use this to chain the tasks such as fab staging deploy or fab production deploy.

提交回复
热议问题