我正在尝试为厨师石墨回购写一个包装食谱
在配方carbon.rb中,出现以下行:
template "#{node['graphite']['base_dir']}/conf/storage-schemas.conf" do
owner node['apache']['user']
group node['apache']['group']
end
Run Code Online (Sandbox Code Playgroud)
在templates/default/storage-schemas.conf中有一个不受我喜欢的storage-schemas.conf文件.我可以内联编辑文件并实现我想要的,但如果我希望能够在不发生合并冲突的情况下保持我的仓库更新,它似乎不是一个好厨师的做法.所以我想知道我是否可以用包装食谱来解决这个问题.
我的第一个虽然是这样的
include_recipe "graphite"
template "#{node['graphite']['base_dir']}/conf/storage-schemas.conf" do
owner node['apache']['user']
group node['apache']['group']
end
Run Code Online (Sandbox Code Playgroud)
我将在基本配方完成后重新运行命令,并将我想要的文件放在wrappercookbook/templates/storage-schemas.conf.erb中.这是一种常见做法吗?它感觉不太干,但我想不出更干净的方式.
Dav*_* S. 27
你很亲密.假设您的包装器手册中有storage-schemas.conf.erb文件的修改版本,您可以这样做:
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
Run Code Online (Sandbox Code Playgroud)
您还可以使用以下行:
r.source "graphite-stuff/my-storage-schemas.conf.erb"
Run Code Online (Sandbox Code Playgroud)
如果您想以不同的方式组织包装器菜谱中的文件.
Ser*_*gio 14
作为Dave答案的替代品,您也可以使用chef-rewind.
https://github.com/bryanwb/chef-rewind
来自github repo的快速使用示例
#file postgresql/recipes/server.rb
template "/var/pgsql/data/postgresql.conf" do
source "postgresql.conf.erb"
owner "postgres"
end
Run Code Online (Sandbox Code Playgroud)
#file my-postgresql/recipes/server.rb
chef_gem "chef-rewind"
require 'chef/rewind'
include_recipe "postgresql::server"
# my-postgresql.conf.erb located inside my-postgresql/templates/default/my-postgresql.conf.erb
rewind :template => "/var/pgsql/data/postgresql.conf" do
source "my-postgresql.conf.erb"
cookbook_name "my-postgresql"
end
Run Code Online (Sandbox Code Playgroud)