Sha256: c16c012474ea6c02984d8cca7eccbfef2d6d8ca57d4955ce3d4b764be3d4b400

Contents?: true

Size: 934 Bytes

Versions: 6

Compression:

Stored size: 934 Bytes

Contents

# frozen_string_literal: true

require 'bolt/error'

# Returns the facts hash for a target.
Puppet::Functions.create_function(:facts) do
  # @param target A target.
  # @return The target's facts.
  # @example Getting facts
  #   facts($target)
  dispatch :facts do
    param 'Target', :target
    return_type 'Hash[String, Data]'
  end

  def facts(target)
    unless Puppet[:tasks]
      raise Puppet::ParseErrorWithIssue.from_issue_and_stack(
        Puppet::Pops::Issues::TASK_OPERATION_NOT_SUPPORTED_WHEN_COMPILING, operation: 'facts'
      )
    end

    inventory = Puppet.lookup(:bolt_inventory) { nil }

    unless inventory
      raise Puppet::ParseErrorWithIssue.from_issue_and_stack(
        Puppet::Pops::Issues::TASK_MISSING_BOLT, action: _('get facts for a target')
      )
    end

    executor = Puppet.lookup(:bolt_executor) { nil }
    executor&.report_function_call('facts')

    inventory.facts(target)
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
bolt-0.21.4 bolt-modules/boltlib/lib/puppet/functions/facts.rb
bolt-0.21.3 bolt-modules/boltlib/lib/puppet/functions/facts.rb
bolt-0.21.2 bolt-modules/boltlib/lib/puppet/functions/facts.rb
bolt-0.21.1 bolt-modules/boltlib/lib/puppet/functions/facts.rb
bolt-0.21.0 bolt-modules/boltlib/lib/puppet/functions/facts.rb
bolt-0.20.7 bolt-modules/boltlib/lib/puppet/functions/facts.rb