我想覆盖说明书包装器中的模板,但模板资源是在提供程序中定义的,而不是在配方中定义的。我一直在重写包装器中的模板,例如本例 http://syshero.org/post/67727745605/override-templates-from-third-party-cookbooks-on
include_recipe "rsyslog"
begin
t = resources(:template => "/etc/rsyslog.conf")
t.source "rsyslog.conf.erb"
t.cookbook "example"
rescue Chef::Exceptions::ResourceNotFound
Chef::Log.warn "could not find template /etc/rsyslog.conf to modify"
end
并且总是按预期工作。
具有我试图更改的配置的 Recipe 是 git_user Recipe https://supermarket.chef.io/cookbooks/git_user
我想要改变的一点是提供商 https://github.com/lxmx/chef-git-user/blob/master/providers/default.rb#L30
尝试使用与我的 Recipe 相同的格式似乎不起作用?
include_recipe "git_user::data_bag"
def load_current_resource
@login = new_resource.login
@home = new_resource.home || (@login == 'root' ? '/root' : "/home/#{@login}")
end
begin
home = @home
r = resources(:template => "#{home}/.ssh/config")
r.cookbook "MY-git_user"
rescue Chef::Exceptions::ResourceNotFound
Chef::Log.warn "could not find MY-git_user::data_bag template to override!"
end
最佳答案
我认为这不是您期望的答案,并且可能不准确,但转得太长而无法发表评论:
lwrp 内部资源是在聚合阶段调用提供程序时编译和聚合的,它们不会在编译时进行处理,因此无法访问它们,因为它们尚不存在。 (一旦lwrp完成,它们就已经收敛了,所以你也不能在收敛时修改它们)。
use_inline_resources documentation用两个表解释这一点(编译然后收敛阶段)。
因此不可能覆盖定义到提供程序中的资源,因为它不会出现在 lwrp 提供程序执行本身的资源列表中。
关于use_inline_resource
:它使来自lwrp内部资源的通知由lwrp资源本身触发,我看到lwrp资源充当提供程序中定义的通知的代理。这允许 lwrp 内的资源通知“配方”资源。
无论有没有 use_inline_resources
,机制都是相同的,内部资源在 lwrp 收敛时创建和收敛。
关于chef-infra - 覆盖 Chef Recipe 模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29304329/