Skip to content

Instantly share code, notes, and snippets.

@vStone
Created December 4, 2012 07:05
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save vStone/4201425 to your computer and use it in GitHub Desktop.
Save vStone/4201425 to your computer and use it in GitHub Desktop.
Puppet Template Headers
Original header used now:
### File managed with puppet ###
## Served by: '<%= scope.lookupvar('::servername') %>'
## Module: '<%= scope.to_hash['module_name'] %>'
## Template source: 'MODULES<%= template_source.gsub(Regexp.new("^#{Puppet::Node::Environment.current[:modulepath].gsub(':','|')}"),"") %>'
Problem: When using puppet apply with relative modulepath, the information can be wrong or messy.
Alternative 1:
--------------
<% module_paths = Puppet::Node::Environment.current[:modulepath].split(':').map{|i| File.expand_path(i) }.join("|") -%>
## Template source: 'MODULES<%= template_source.gsub(Regexp.new("^#{module_paths}"),"") %>'
Adds more complexity (expand paths) but is portable and can be copy pasted between files
Alternative 2:
--------------
## Template source: 'MODULES/<%= scope.to_hash['module_name'] %>/templates/test.txt.erb'
Easy but needs to be adjusted for every template.
Alternative 3:
--------------
## Template Source: 'MODULES/<%= scope.to_hash['module_name'] %>/<%= template_source.sub(Regexp.new('^.*\/(templates\/.*)$'), '\1') %>
Not that complex but might be wrong when there is another /templates/ section somewhere in the path.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment