在结构中添加环境变量的最佳方法? [英] Best way to add an environment variable in fabric?

查看:67
本文介绍了在结构中添加环境变量的最佳方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将一些值从Fabric传递到远程环境中,但我没有很好的方法来做到这一点.到目前为止,我想出的最好的方法是:

I would like to pass a few values from fabric into the remote environment, and I'm not seeing a great way to do it. The best I've come up with so far is:

with prefix('export FOO=BAR'):
    run('env | grep BAR')

这似乎确实有效,但似乎有点破绽.

This does seem to work, but it seems like a bit of a hack.

我查看了GIT存储库,它看起来像是 issue#263 .

I looked in the GIT repository and it looks like this is issue #263.

推荐答案

从Fabric 1.5(已发布)开始,

As of fabric 1.5 (released), fabric.context_managers.shell_env does what you want.

    with shell_env(FOO1='BAR1', FOO2='BAR2', FOO3='BAR3'):
        local("echo FOO1 is $FOO1")

这篇关于在结构中添加环境变量的最佳方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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