Template variable for which recipe and template a file was expanded from


#1

I’d like to put a notice in the config files managed by chef to inform
other sysadmins that a particular file is under Chef management and to not
make ad-hoc changes. This isn’t so important on “production” machines, as
it’s understood that those machines have procedures associated with making
changes, but especially as test, prototype, and even dev machines are
folded into Chef management, putting in a notice that says “This file
originated from Chef recipe: COOKBOOK_NAME::RECIPE_NAME from the template
file XYZ.erb” would be useful. I was wondering if there was already a
facility for these variables that might already be passed to the template
engine, and if not, if there was a convenient way to add them across all
templates without having to hack them into every template resource.

– William


#2

both ‘cookbook_name’ and ‘recipe_name’ will evaluate in the Recipe DSL.

You can bind them to a template with the standard ‘variables’ parameter.

–AJ

On 1 August 2012 10:20, William McVey wam-chef@wamber.net wrote:

I’d like to put a notice in the config files managed by chef to inform other
sysadmins that a particular file is under Chef management and to not make
ad-hoc changes. This isn’t so important on “production” machines, as it’s
understood that those machines have procedures associated with making
changes, but especially as test, prototype, and even dev machines are folded
into Chef management, putting in a notice that says "This file originated
from Chef recipe: COOKBOOK_NAME::RECIPE_NAME from the template file XYZ.erb"
would be useful. I was wondering if there was already a facility for these
variables that might already be passed to the template engine, and if not,
if there was a convenient way to add them across all templates without
having to hack them into every template resource.

– William