Sha256: a66ad39b1a42e32be786d627efe3226a5f30845475c07448815e28fafd0ba541

Contents?: true

Size: 1.11 KB

Versions: 28

Compression:

Stored size: 1.11 KB

Contents

# frozen_string_literal: true

require_relative '../../../puppet/file_system'

Puppet::Parser::Functions.newfunction(
  :file, :arity => -2, :type => :rvalue,
         :doc => "Loads a file from a module and returns its contents as a string.

  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
    raise Puppet::ParseError, _("Could not find any files from %{values}") % { values: vals.join(", ") }
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
puppet-8.10.0 lib/puppet/parser/functions/file.rb
puppet-8.10.0-x86-mingw32 lib/puppet/parser/functions/file.rb
puppet-8.10.0-x64-mingw32 lib/puppet/parser/functions/file.rb
puppet-8.10.0-universal-darwin lib/puppet/parser/functions/file.rb
puppet-8.9.0 lib/puppet/parser/functions/file.rb
puppet-8.9.0-x86-mingw32 lib/puppet/parser/functions/file.rb
puppet-8.9.0-x64-mingw32 lib/puppet/parser/functions/file.rb
puppet-8.9.0-universal-darwin lib/puppet/parser/functions/file.rb
puppet-8.8.1 lib/puppet/parser/functions/file.rb
puppet-8.8.1-x86-mingw32 lib/puppet/parser/functions/file.rb
puppet-8.8.1-x64-mingw32 lib/puppet/parser/functions/file.rb
puppet-8.8.1-universal-darwin lib/puppet/parser/functions/file.rb
puppet-8.7.0 lib/puppet/parser/functions/file.rb
puppet-8.7.0-x86-mingw32 lib/puppet/parser/functions/file.rb
puppet-8.7.0-x64-mingw32 lib/puppet/parser/functions/file.rb
puppet-8.7.0-universal-darwin lib/puppet/parser/functions/file.rb
puppet-8.6.0 lib/puppet/parser/functions/file.rb
puppet-8.6.0-x86-mingw32 lib/puppet/parser/functions/file.rb
puppet-8.6.0-x64-mingw32 lib/puppet/parser/functions/file.rb
puppet-8.6.0-universal-darwin lib/puppet/parser/functions/file.rb