Created
December 4, 2012 07:05
-
-
Save vStone/4201425 to your computer and use it in GitHub Desktop.
Puppet Template Headers
This file contains hidden or 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
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