chef-infra - 覆盖 Chef Recipe 模板

标签 chef-infra

我想覆盖说明书包装器中的模板,但模板资源是在提供程序中定义的,而不是在配方中定义的。我一直在重写包装器中的模板,例如本例 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/

相关文章:

ruby - 如何用vagrant和chef创建虚拟主机

chef-infra - 尝试使用 Chef 在 Windows 上以指定用户身份运行执行和批处理

chef-infra - 尝试创建两个目录的符号链接(symbolic link)时 Chef 链接错误

chef-infra - 如何在 Test Kitchen .kitchen.yml 文件中指定 Chef Solo 的版本?

mysql - Chef Recipe 将值添加到 mysql 表

configuration - 为什么不应该使用Chef/Puppet逐行更改配置文件?

linux - Chef-server-ctl 重新配置/在 Chef 服务器上创建管理员用户

chef-infra - gitlab-ctl 重新配置 : Unable to determine node name

php - 从 Vagrant 中的 Chef Recipe 运行 PHP 脚本时 MySQL 不工作

ruby - Chef knife 命令不显示 ssl 子命令