Created
January 31, 2012 21:49
-
-
Save fujin/1713157 to your computer and use it in GitHub Desktop.
template override between cookbooks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template "/tmp/foo.rb" | |
source "foo.rb.erb" | |
cookbook "banana" | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
include_recipe "whatever_cookbook::foo" | |
begin | |
t = resources(:template => "/tmp/foo.rb") | |
t.source "bonkers.rb.erb" | |
t.cookbook "definitely_not_banana" | |
rescue Chef::Exceptions::ResourceNotFound | |
Chef::Log.warn "could not find template /tmp/foo.rb to modify" | |
end |
foo.rb
is missing a do
in the first line.
Excellent, thanks
Thanks for this. You saved my day!
Thanks! did the trick.
How do you send variables to the overridden template?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Line 4, you can also use the more terse notation,
Fun tricks can be played by modifying the variables passed into the template, too, allowing you to override the template from an "upstream" cookbook without actually changing the code. That can avoid the "cookbook shadowing" deprecation warnings in some configurations.