How to add header to all files/templates?

369 views
Skip to first unread message

robbyt

unread,
Aug 6, 2009, 1:53:17 AM8/6/09
to Puppet Users
Hello All!

I would like to automatically add a header to all files/templates that
puppet manages on my servers. Something like "#if you break, my puppet
will fix it!!"

Is this possible?

Nicolas Szalay

unread,
Aug 6, 2009, 3:03:04 AM8/6/09
to puppet...@googlegroups.com

Probably by creating a custom type that would works like

header_file { "/etc/myapp/myfile":
owner => blah
group => xxxx
source => "puppet://files/app/myapp/myfile"
}

the original "myfile" not having header of course. See
http://reductivelabs.com/trac/puppet/wiki/PracticalTypes that gives an
example of custom type. Moreover, the example looks like what you want
to do.

Regards,

Nico.

signature.asc

Sam Rowe

unread,
Aug 6, 2009, 8:57:06 AM8/6/09
to puppet...@googlegroups.com

Not sure if this is the best way, but you could set a variable in your site.pp:

$myheader = "whatever"

I'm pretty sure the template will have access to that variable, but
I'm not positive. Another route would be to create a custom parser
function that sets the variable.... It's simpler than it sounds. :)

Ohad Levy

unread,
Aug 6, 2009, 9:51:04 AM8/6/09
to puppet...@googlegroups.com
templates can accept a multiple list of erb files, therefor you could easly create a define that always include another template(header)

for example (its up to you to test if it works ;))

define mytemplate($template) {
  file {$name:
    content => template("my header file",$template),
  }
}

and than you use it:

mytemplate("/etc/motd":
  template => "my template",
}


hope it helps,
Ohad
Reply all
Reply to author
Forward
0 new messages