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
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