简体   繁体   English

在厨师食谱中分配环境变量的最佳方法是什么?

[英]What is the best way to assign environment variable inside chef recipe?

I want to assign a system variable within chef recipe 我想在厨师食谱中分配系统变量
I am using the following code: 我正在使用以下代码:

env 'DEF_ADDR' do
  value "http://#{node['ipaddress']}"
end  

However, I am getting the below error on executing the recipe 但是,在执行配方时出现以下错误

ERROR: Cannot find a resource for env on redhat version 6.6 错误:在redhat 6.6版上找不到env的资源

There is no consistent way to set global environment variables on Unix. 在Unix上没有一致的方法来设置全局环境变量。 Some distros support global-level shell includes via things like /etc/profile.d and the like, but this will have no effect on things run outside of a shell like direct SSH execution or running as a service. 一些发行版支持全局级别的shell包括通过/etc/profile.d之类的东西,但这不会影响在shell外部运行的东西(例如直接SSH执行或作为服务运行)。

The env resource seems to be only for Windows environments: env资源似乎仅适用于Windows环境:

Use the env resource to manage environment keys in Microsoft Windows. 使用env资源在Microsoft Windows中管理环境密钥。

If you want to define an environment variable only for the Chef Run, you can use Ruby: 如果只想为Chef Run定义环境变量,则可以使用Ruby:

ENV['DEF_ADDR'] = "http://#{node['ipaddress']}"

But this will only be accessible during the Chef Run. 但这只能在“厨师运行”期间访问。

If you want to define a system-wide environment variable, maybe the etc_environment cookbook could help you with that: 如果您想定义系统范围的环境变量,那么etc_environment Cookbook可能会帮助您:

node.default['etc_environment']['DEF_ADDR'] = "http://#{node['ipaddress']}"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM