Skip to content

Instantly share code, notes, and snippets.

@pbrit
Last active August 29, 2015 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pbrit/a22d9fd214e428467c64 to your computer and use it in GitHub Desktop.
Save pbrit/a22d9fd214e428467c64 to your computer and use it in GitHub Desktop.
require 'md5'
module Puppet::Parser::Functions
newfunction(:file_tree_hash, :type => :rvalue, :arity => 1, :doc => <<-EOS
Returns MD5 has for given prefix. It travers file tree recursively.
EOS
) do |arguments|
prefix = arguments[0]
content = Dir .glob("#{prefix}/**/*") \
.sort \
.reject { |el| File.directory?(el) } \
.map { |el| content = File.read(el); MD5.md5(content).to_s } \
.join('')
MD5.md5(content).to_s
end
end
node 'foo' {
$update_time = file_tree_hash("/foo/bar")
notice($update_time)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment