如何使用Chef设置环境变量? [英] How to set environment variable using Chef?

查看:72
本文介绍了如何使用Chef设置环境变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个与此类似的问题,但无法使其正常工作:
我想简单地设置一个env变量,然后使用它:

Theres a similar question to this, but cant manage it to work: I want to simply set an env variable, then use it:

execute "start zookeeper" do
    cwd "/opt/zookeeper-3.4.5/bin"
    command "./zkServer.sh start"
    environment "JVMFLAGS" => "-Xmx#{heap_jvm} -Xms#{heap_jvm}"
    user "root"
    action :run
end

我也尝试过使用bash来 export JVMFLAGS ='-blabla' ,但是它仍然可以运行没有设置为变量。有什么问题阻止我的sh脚本检查变量吗?
我可以像模板一样使用sh并替换JVMFLAGS的出现...但是我想检查是否有更好的解决方案。.

I've also tried using bash to "export JVMFLAGS='-blabla'" but still it runs the sh with none set to the variable. Is there some issue preventing my sh script from checking the variable? I could use the sh like a template and replace the ocurrence of JVMFLAGS... But i want to check if theres a better solution..

推荐答案

您是否尝试过在 execute 块之前通过Ruby设置环境变量? Chef实际上建议使用ENV (请参见该页面上的 note )。

Have you tried setting environment variable through Ruby just before the execute block? Chef actually recommends using ENV (See the note on that page).

ENV['JVMFLAGS'] = "-Xmx#{heap_jvm} -Xms#{heap_jvm}"

另一种可能性是将JVMFLAGS添加到命令本身。

Another possibility is to add JVMFLAGS to the command itself.

execute "start zookeeper" do
  [...]
  command "JVMFLAGS=-Xmx#{heap_jvm} -Xms#{heap_jvm} ./zkServer.sh start"
  [...]
end

这篇关于如何使用Chef设置环境变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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