厨师-读取Chef recipe.rb文件中的外部属性 [英] Chef - Read external properties in chef recipe.rb files

查看:112
本文介绍了厨师-读取Chef recipe.rb文件中的外部属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Chef部署工具的新手,并且想在我的一个用例中使用它。我能够调用POST调用来休息端点。但是具有如下所示的硬编码的url和json数据:

I am new to Chef deployment tool and would like to use it for one of my use case. I am able to invoke a POST call to rest endpoint. But with the hardcoded url and json data as shown below:

recipe / default.rb

template '/etc/response.txt' do
        owner "root"
        group "root"
        mode "0644"
        source "response.erb"
        variables({
                response:Chef::HTTP.new('https://abc.om/').post('/api/v1/something',
                { "data1": "value1", "data2": "value2"},
                {'Accept'=> 'application/json', 'Content-Type'=>'application/json'})
        })
end

我想使用动态url,json和其他请求参数的值。我希望将其外部化,例如在环境文件中(我们在Java Web应用程序中的方式),以便在节点上运行Chef-Client之前,用户可以为请求参数提供值。

I would like to use dynamic value of url, json and other request parameters. I want it to be externalized such as in environments file (the way we do it in java web applications) so that before running the chef-client on nodes, user can provide values for request parameters. How can we achieve that in chef?

推荐答案

chef语法(recipe dsl)在ruby之上运行。因此,您可以利用ruby的力量动态地进行操作-用厨师的话,您可以在编译阶段融合阶段

chef syntax (recipe dsl) runs on top of ruby. thus you can leverage the power of ruby to dynamically -- in chef terms, you can do it in compilation phase or in convergence phase:


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

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

  • 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.

最好在融合阶段进行此操作,就可以使用 ruby​​_block 和/或 http_request 资源。

best to do it in the convergence phase and you can achieve it using the ruby_block and\or http_request resources.

如果您想在菜谱中包含静态文件,则将其放在 COOKBOOK_NAME / files / default中并根据需要阅读。参见 cookbook_file 资源。

if you would like to have a static file within your cookbook, then place it within COOKBOOK_NAME/files/default and read it as you please. see cookbook_file resource.

这篇关于厨师-读取Chef recipe.rb文件中的外部属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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