Fabric + DigitalOcean:不可见环境变量? [英] Fabric + DigitalOcean: unvisible ENVIRONMENT VARIABLE?

查看:250
本文介绍了Fabric + DigitalOcean:不可见环境变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在DigitalOcean上有服务器,我使用fabric来部署我的代码。而我的代码依赖于环境变量(烧瓶配置)。我今天遇到一个奇怪的问题:在服务器上的 /root/.bashrc 中我添加了下一行

  export CONFIG = / path / to / conf 

当我在远程控制台上执行

 >>> echo $ CONFIG 
>>> / path / to / conf#result,因为它应该是

但是在 fabfile 我有一个函数

  def show():
run(echo $ CONFIG)

它打印一个空字符串。为什么?
提前感谢

解决方案

不应该是这样,默认情况下Fabric使用 -l <​​/ code>标志应该是使bash的行为好像已被调用为登录shell(请参阅下面的INVOCATION)。 / p>

我也无法再现您的问题:

  $ fab -H home test_bash 
[home]执行任务'test_bash'
[home] run:grep FOO $ HOME / .bashrc
[home] out:export FOO =BAR
[home] out:

[home] run:echo $ FOO
[home] out:BAR
[home] out:

所以我的猜测是你更改了 env.shell ,或者你'不是连接作为用户,你正在设置这个bash导出。 (请注意,在Fabric使用中 run() sudo()不同)


I have server on DigitalOcean and I use fabric for deploying my code. And my code is dependent on environment variables (flask config). I've faced one strange trouble today: on server in /root/.bashrc I've added next line

export CONFIG=/path/to/conf

And when I executing on remote console

>>> echo $CONFIG
>>> /path/to/conf  # result, as it should be

But in fabfile I have a function

def show():
    run("echo $CONFIG")

And it prints an empty string. WHY? Thanks in advance!

解决方案

This shouldn't be the case, as by default Fabric uses the -l flag which is supposed to Make bash act as if it had been invoked as a login shell (see INVOCATION below).

I am also not able to reproduce your issue:

$ fab -H home test_bash
[home] Executing task 'test_bash'
[home] run: grep FOO $HOME/.bashrc
[home] out: export FOO="BAR"
[home] out:

[home] run: echo $FOO
[home] out: BAR
[home] out:

So my guess is that you've changed the env.shell, or that you're not connecting as the root user which is where you're setting this bash export. (Note that run() isn't the same a sudo() in Fabric usage)

这篇关于Fabric + DigitalOcean:不可见环境变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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