Chef cookbook that provides an LWRP to wrap the template resource to provide more user flexibility
The overridable cookbook provides an LWRP that makes it simple to provide maximum user flexibility in cookbook templates. When used instead of the standard Template resource (http://wiki.opscode.com/display/chef/Resources#Resources-Template), it provides a means for a cookbook user to override each template with either the user's own template or a concrete file.
node['overridable']['template']['enabled']
- Default: true
. Setting to false
node['overridable']['template']['files_enabled']
- Default: true
. Setting to false
node['overridable']['template']['templates_enabled']
- Default: true
. Setting tofalse
disables the ability to override existing templates with new templatesTo use the LWRP in your cookbook, simply add depends 'overridable'
to the
cookbook's metadata.rb and substitute any template
resources
with overridable_template
When config file customization is needed on a cookbook that takes advantage of overridable template, two options are available:
Copy the cookbook's provided template file to a new file of the same name
within the cookbook's templates/overrides directory.
Ex: templates/default/web_app.conf.erb
maps to templates/default/overrides/web_app.conf.erb
Additional attributes can be set in a new attributes file added to the cookbook
attributes/ directory and referenced through the @node
reference exposed to
the Erb template. File-specificity rules are honored, so the override/
path can
exist in a host-specific directory instead for instance.
A file can replace the template behavior entirely (ensure you have dealt with
any dynamic aspect of the config you're replacing). The file must be named
the same as the destination path of the template resource
Ex: /etc/ntp.conf
would be named ntp.conf
within the cookbook's files/
directory
overridable_template
calls that refer to the same base filename withinAuthor:: Michael Leinartas ([email protected])
Copyright 2011, Michael Leinartas
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.