python fabric是否支持动态设置env.hosts? [英] Does python fabric support dynamic set env.hosts?

查看:173
本文介绍了python fabric是否支持动态设置env.hosts?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想动态更改env.hosts,因为有时我想先部署到一台计算机上,检查是否正常,然后再部署到多台计算机上. 当前,我需要先设置env.hosts,如何在脚本启动时在方法而不是全局中设置env.hosts?

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 first, how could I set the env.hosts in a method and not in global at script start?

推荐答案

是的,您可以动态设置env.hosts.我们使用的一种常见模式是:

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...

您将使用它来链接诸如fab staging deployfab production deploy之类的任务.

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

这篇关于python fabric是否支持动态设置env.hosts?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆