Chef:从Shell环境变量读取属性值 [英] Chef: reading attribute value from shell environment variables

查看:119
本文介绍了Chef:从Shell环境变量读取属性值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在厨师食谱的属性文件中读取环境变量的值。许多帖子都描述了我可以使用ruby的ENV []实现我想要的。

I am trying to read value of an environment variable in attributes file of chef cookbook. Many posts have described that i can use ENV[] of ruby to achieve what i want.

我的属性文件如下:

default['some_object']['some_attribute'] = ENV['SOME_ENV_VAR']

在运行配方时,似乎结果为空字符串。

While running recipe, it seems to result in empty string. Any pointers?

推荐答案

假定您所描述的是正确的方法(并非如此),请注意您需要在执行 chef-client 的节点上设置环境变量。

assume that what you describe is the right way to do so (which is not), note that you need to set the environment variable on the node where you execute chef-client.

chef-client 执行有几个阶段:


  • 编译阶段:所有配方均按照扩展后指定的顺序加载运行列表。

  • 收敛阶段:按照运行列表标识的顺序执行每个资源,然后按列出每个资源的顺序执行在每个食谱中。 ...每个动作都会配置系统的特定部分。

  • compilation phase: all recipes are loaded in the order specified by the expanded run-list.
  • convergence phase: Each resource is executed in the order identified by the run-list, and then by the order in which each resource is listed in each recipe. ...each action configures a specific part of the system.

有关此阶段的厨师客户的更多信息,请参见厨师-客户端概述

for more information about chef-client about the phase, see chef-client overview.

对环境变量的评估,即 ENV ['SOME_ENV_VAR'] 发生在编译阶段。您真正应该做的是使用 json属性

the evaluation of your environment variable, namely ENV['SOME_ENV_VAR'] happens on the compilation phase. what you should really do, is to use json attribute:


您可以通过包含 -json-attributes提供自定义属性 (我强烈建议您访问文档,因为它包含示例)

you can provide custom attributes by including --json-attributes (i strongly advise you to visit the documentation, since it holds examples) in chef-client

-j PATH ,--json-attributes PATH
包含JSON数据的文件的路径。用于设置第一个客户端运行。对于使用选项-i的所有将来运行,这些属性应保留在厨师服务器中。

-j PATH, --json-attributes PATH The path to a file that contains JSON data. Used to setup the first client run. For all the future runs with option -i the attributes are expected to be persisted in the chef-server.

您始终可以使用以下环境变量:为您设置以构造一个json结构,然后在执行它时将其提供给Chef-client。

you can always use the environment variables that are set for you to construct a json structure and then feed it to chef-client when you execute it.

这篇关于Chef:从Shell环境变量读取属性值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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