summaryrefslogtreecommitdiffstats
path: root/lib/puppet/parser/functions/file.rb
blob: d13b01eded6191b7591127f545f5f5dcb3975789 (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 #{vals.join(", ")}"
            end
end