替换包装食谱中的模板 [英] Replacing a template in a wrapper cookbook

查看:39
本文介绍了替换包装食谱中的模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为首席石墨仓库

在配方carbon.rb中,出现以下几行:

In the recipe carbon.rb, the following lines occur:

template "#{node['graphite']['base_dir']}/conf/storage-schemas.conf" do
  owner node['apache']['user']
  group node['apache']['group']
end

其中的template / default / storage-schemas.conf中有一个存储-我不喜欢的schemas.conf文件。我可以内联编辑文件并实现所需的功能,但是如果我希望能够使我的仓库保持最新状态而不会发生合并冲突,那么这似乎不是厨师的好习惯。所以我想知道是否可以用包装食谱来解决这个问题。

where in templates/default/storage-schemas.conf there is a storage-schemas.conf file that is not to my liking. I can edit the file inline and achieve what I want, but it doesn't seem like a good chef practice if I want to be able to keep my repo up to date without merge conflicts. So I was wondering if I could solve this with a wrapper cookbook.

我的第一个虽然是这样的

My first though was something like

include_recipe "graphite"
template "#{node['graphite']['base_dir']}/conf/storage-schemas.conf" do
  owner node['apache']['user']
  group node['apache']['group']
end

在这里我会重新运行基本配方完成后的命令,然后将所需的文件放入wrappercookbook / templates / storage-schemas.conf.erb中。这是常见的做法吗?感觉不是很干,但是我想不出一种更干净的方法。

where I would just rerun the command after the base recipe finished and put the file I wanted in wrappercookbook/templates/storage-schemas.conf.erb. Is this a common practice? It doesn't feel very DRY, but I can't think of a cleaner way.

推荐答案

您非常接近。假设您的包装食谱中有storage-schemas.conf.erb文件的修改版本,则可以执行以下操作:

You're pretty close. Assuming you have a modified version of the storage-schemas.conf.erb file in your wrapper cookbook, you can just do:

include_recipe "graphite"
begin
  r = resources(:template => "#{node['graphite']['base_dir']}/conf/storage-schemas.conf")
  r.cookbook "my-cookbook"
rescue Chef::Exceptions::ResourceNotFound
  Chef::Log.warn "could not find template to override!"
end

您还可以使用以下行:

r.source "graphite-stuff/my-storage-schemas.conf.erb"

如果您想以其他方式组织包装指南中的文件。

if you want to organize the files in your wrapper cookbook in a different way.

这篇关于替换包装食谱中的模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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