diff options
author | mail_redacted_for_web | 2016-01-05 13:27:26 -0800 |
---|---|---|
committer | mail_redacted_for_web | 2016-01-05 13:27:26 -0800 |
commit | 9a876a61e730f1c17063ad0593c3b37625503b5e (patch) | |
tree | c93741be83ef640c860297e0efe3bbb3d86bfca6 /site/no_fail_file/lib/puppet | |
parent | a9d3be58aa816a0b909efa05cbb714c0e94c21be (diff) | |
parent | 752f2ef87bb56895f5a63c89fd01fe0ed0c623be (diff) | |
download | control-repo-template-9a876a61e730f1c17063ad0593c3b37625503b5e.tar.bz2 |
Merge pull request #9 from npwalker/2015_3_prep
Changes for PE2015.3.0
Diffstat (limited to 'site/no_fail_file/lib/puppet')
-rw-r--r-- | site/no_fail_file/lib/puppet/parser/functions/no_fail_file.rb | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/site/no_fail_file/lib/puppet/parser/functions/no_fail_file.rb b/site/no_fail_file/lib/puppet/parser/functions/no_fail_file.rb new file mode 100644 index 0000000..3819ebf --- /dev/null +++ b/site/no_fail_file/lib/puppet/parser/functions/no_fail_file.rb @@ -0,0 +1,36 @@ +require 'puppet/file_system' + +Puppet::Parser::Functions::newfunction( + :no_fail_file, :arity => -2, :type => :rvalue, + :doc => "Loads a file from a module and returns its contents as a string. + + This is a replacement to the file function that returns nothing + if the file specified cannot be found instead of erroring out. + + The argument to this function should be a `<MODULE NAME>/<FILE>` + reference, which will load `<FILE>` from a module's `files` + directory. (For example, the reference `mysql/mysqltuner.pl` will load the + file `<MODULES DIRECTORY>/mysql/files/mysqltuner.pl`.) + + This function can also accept: + + * An absolute path, which can load a file from anywhere on disk. + * Multiple arguments, which will return the contents of the **first** file + found, skipping any files that don't exist. + " +) do |vals| + path = nil + vals.each do |file| + found = Puppet::Parser::Files.find_file(file, compiler.environment) + if found && Puppet::FileSystem.exist?(found) + path = found + break + end + end + + if path + Puppet::FileSystem.read_preserve_line_endings(path) + else + nil + end +end |