summaryrefslogtreecommitdiffstats
path: root/lib/puppet/parser/functions/file.rb
blob: f78823d3a5f84caaebfe324caf5c07d6df866aae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# 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