Skip to content

Commit

Permalink
- add location finding
Browse files Browse the repository at this point in the history
  • Loading branch information
jordansissel committed Feb 21, 2012
1 parent c3dbac2 commit c38ac38
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
16 changes: 16 additions & 0 deletions where-art-thou/README.md
@@ -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"]
3 changes: 3 additions & 0 deletions where-art-thou/whereareyou/manifests/init.pp
@@ -0,0 +1,3 @@
class whereareyou {
notice(template("whereareyou/example.erb"))
}
10 changes: 10 additions & 0 deletions where-art-thou/whereareyou/templates/example.erb
@@ -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
%>

0 comments on commit c38ac38

Please sign in to comment.