summaryrefslogtreecommitdiffstats
path: root/lib/puppet/parser/functions/file.rb
blob: 47b3f96e0f4ee19d8b3ce5061dabf5b5c347653e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# Returns the contents of a file
Puppet::Parser::Functions::newfunction(:file, :type => :rvalue,
        :doc => "Return the contents of a file.  Multiple files
        can be passed, and the first file that exists will be read in.") do |vals|
            ret = nil
            vals.each do |file|
                unless file =~ /^#{File::SEPARATOR}/
                    raise Puppet::ParseError, "Files must be fully qualified"
                end
                if FileTest.exists?(file)
                    ret = File.read(file)
                    break
                end
            end
            if ret
                ret
            else
                raise Puppet::ParseError, "Could not find any files from %s" %
                    vals.join(", ")
            end
end