Sha256: 52d6e9d698d9ba5873c720c8e5b2035addc9ddbf09069672b6ac8df31860f5ee

Contents?: true

Size: 1.04 KB

Versions: 32

Compression:

Stored size: 1.04 KB

Contents

# frozen_string_literal: true

# Read a file on localhost and return its contents using ruby's `File.read`. This will
# only read files on the machine you run Bolt on.
Puppet::Functions.create_function(:'file::read', Puppet::Functions::InternalFunction) do
  # @param filename Absolute path or Puppet file path.
  # @return The file's contents.
  # @example Read a file from disk
  #   file::read('/tmp/i_dumped_this_here')
  # @example Read a file from the modulepath
  #   file::read('example/VERSION')
  dispatch :read do
    scope_param
    required_param 'String', :filename
    return_type 'String'
  end

  def read(scope, filename)
    # Send Analytics Report
    Puppet.lookup(:bolt_executor) {}&.report_function_call(self.class.name)

    found = Puppet::Parser::Files.find_file(filename, scope.compiler.environment)
    unless found && Puppet::FileSystem.exist?(found)
      raise Puppet::ParseErrorWithIssue.from_issue_and_stack(
        Puppet::Pops::Issues::NO_SUCH_FILE_OR_DIRECTORY, file: filename
      )
    end

    File.read(found)
  end
end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
bolt-3.1.0 bolt-modules/file/lib/puppet/functions/file/read.rb
bolt-3.0.1 bolt-modules/file/lib/puppet/functions/file/read.rb
bolt-3.0.0 bolt-modules/file/lib/puppet/functions/file/read.rb
bolt-2.44.0 bolt-modules/file/lib/puppet/functions/file/read.rb
bolt-2.42.0 bolt-modules/file/lib/puppet/functions/file/read.rb
bolt-2.40.2 bolt-modules/file/lib/puppet/functions/file/read.rb
bolt-2.40.1 bolt-modules/file/lib/puppet/functions/file/read.rb
bolt-2.38.0 bolt-modules/file/lib/puppet/functions/file/read.rb
bolt-2.37.0 bolt-modules/file/lib/puppet/functions/file/read.rb
bolt-2.36.0 bolt-modules/file/lib/puppet/functions/file/read.rb
bolt-2.35.0 bolt-modules/file/lib/puppet/functions/file/read.rb
bolt-2.34.0 bolt-modules/file/lib/puppet/functions/file/read.rb
bolt-2.33.2 bolt-modules/file/lib/puppet/functions/file/read.rb
bolt-2.33.1 bolt-modules/file/lib/puppet/functions/file/read.rb
bolt-2.32.0 bolt-modules/file/lib/puppet/functions/file/read.rb
bolt-2.31.0 bolt-modules/file/lib/puppet/functions/file/read.rb
bolt-2.30.0 bolt-modules/file/lib/puppet/functions/file/read.rb
bolt-2.29.0 bolt-modules/file/lib/puppet/functions/file/read.rb
bolt-2.28.0 bolt-modules/file/lib/puppet/functions/file/read.rb
bolt-2.27.0 bolt-modules/file/lib/puppet/functions/file/read.rb