Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c3dbac2
commit c38ac38
Showing
3 changed files
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,16 @@ | |||
# Find where a module is loaded from | |||
|
|||
This trick uses a template, $settings::modulepath, and __FILE__ from a template | |||
to find the location of a template (and thus its module) relative to the puppet | |||
module path. | |||
|
|||
|
|||
From this directory, run: | |||
|
|||
% puppet apply --modulepath . -e 'include whereareyou' | |||
|
|||
Output: | |||
|
|||
notice: Scope(Class[Whereareyou]): [".", "whereareyou/templates/example.erb"] | |||
|
|||
The output above is ["module path for this file", "file path relative to the modulepath"] |
This file contains 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 file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,3 @@ | |||
class whereareyou { | |||
notice(template("whereareyou/example.erb")) | |||
} |
This file contains 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 file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,10 @@ | |||
<%= | |||
scope.lookupvar("settings::modulepath").split(":").collect do |path| | |||
expandedpath = File.expand_path(path) | |||
if __FILE__.start_with?(expandedpath) | |||
[path, __FILE__.gsub(expandedpath + "/", "")] | |||
else | |||
nil | |||
end | |||
end.select { |f| !f.nil? }.first | |||
%> |