简体   繁体   English

通过从属性文件动态传递值来创建厨师配方

[英]Create chef recipe by passing values dynamically, from properties file

I created a chef recipe which has the installation of a specific rpm mentioned in it. 我创建了一个厨师食谱,其中安装了提到的特定rpm。 This rpm has a version number which needs to be loaded dynamically from a properties file (which is itself created dynamically). 该rpm的版本号需要从属性文件(它本身是动态创建的)中动态加载的。 This chef recipe then needs to be loaded into the chef server. 然后需要将该厨师食谱加载到厨师服务器中。

remote_file "Core_feature.rpm" do
path   "#{src_loc}core_feature_v91-2.noarch.rpm"

Here, v91-2 is the value which needs to go in dynamically into the recipe, by reading from a properties file. 在这里, v91-2是需要通过从属性文件读取而动态输入到配方中的值。

Is this achievable? 这可以实现吗? If yes, how do I go on to implement it.(Have no idea on ruby)! 如果是的话,我该如何继续实施它(对红宝石一无所知)!

You have a few options. 您有几种选择。 The best, in my opinion, is to use a json file rather than a properties file. 我认为最好的方法是使用json文件而不是属性文件。 You can then use the -j flag on your chef-client call to read the json file in as normal attributes on your node. 然后,您可以在chef-client调用上使用-j标志,以在节点上作为normal属性读取json文件。 The major caveat there is that normal attributes persist from one chef run to the next, so you'd need to be sure they're being re-set with each chef run. 这里的主要警告是, normal属性从一个厨师运行到下一个厨师运行都会持续存在,因此您需要确保在每次厨师运行时都重新设置它们。

Alternately, you can have jenkins use knife to set the attributes directly on the node. 或者,您可以让詹金斯使用美工刀直接在节点上设置属性。 You'll need a plugin knife node attribute set ... . 您需要一个插件 knife node attribute set ... OR you could set it on the environment or role, if those are viable options, but they'll involve pulling the environment or role from the server, modifying it, and then pushing it back up. 或者,如果可以的话,也可以在环境或角色上进行设置,但是它们将涉及从服务器中拉出环境或角色,对其进行修改,然后再将其向上备份。

Another option is to use ruby to read your properties file as part of your attributes/xxxx.rb file. 另一种选择是使用ruby读取属性文件作为attributes / xxxx.rb文件的一部分。 You could then set the node attributes from it at whatever precedent level you want. 然后,可以根据需要设置其优先级的节点属性。

attributes/default.rb 属性/ default.rb

properties = IO.read('/path/to/properties/file')
# parse properties and set node attributes like this
node.default[:something] = <your value>

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

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