chef rewind cookbook_file definition from a wrapper cookbook recipe

安稳与你 提交于 2019-12-22 01:32:26

问题


I am using an cookbook github.com opscode-cookbooks/openldap. I wrote an wrapper cookbook "lab_openldap" that includes "openldap::server" recipe.

The server.rb recipe uses following clausule to upload the PEM file from cookbooks files/ssl/*.pem to server to the location node['openldap']['ssl_cert'].

if node['openldap']['tls_enabled'] && node['openldap']['manage_ssl']
  cookbook_file node['openldap']['ssl_cert'] do
    source "ssl/#{node['openldap']['server']}.pem"
    mode 00644
    owner "root"
    group "root"
  end
end

The PEM is tried to be read from "openldap" cookbook file/ssl/#{node['openldap']['server']}.pem" location.

I have my PEM file in wrapper "lab_openldap" cookbook file/ssl/#{node['openldap']['server']}.pem" location.

Is it possible to modify the "lab_openldap::server.rb" recipe to load PEM from a wrapper cookbook?

Notes: I am aware of https://github.com/bryanwb/chef-rewind but it does not seem to manage this situation.

Update

The provided answer using r.resource is correct.

Actually the issue in the particular code is on "source" keyword that according to http://docs.opscode.com/resource_cookbook_file.html refers to the location of a file in the /files directory in a cookbook located in the chef-repo.

r = resources("cookbook_file[#{node['openldap']['ssl_cert']}]")
r.cookbook('lab_openldap')

cookbook_file node['openldap']['ssl_cert'] do
    source "ssl/#{node['openldap']['server']}.pem"
    mode 00644
    owner "root"
    group "root"
end

回答1:


Of course it is! You just need to set the cookbook attribute on the resource when you wrap it. By default, it's "the current cookbook", but you can change it:

r = resources("cookbook_file[#{node['openldap']['ssl_cert']}]")
r.cookbook('my_wrapper_cookbook')

If you look at Bryan's Chef Rewind, you'll see it does the same thing



来源:https://stackoverflow.com/questions/21045855/chef-rewind-cookbook-file-definition-from-a-wrapper-cookbook-recipe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!