Sha256: 4729c51b6dc673099428128d7306e794edef96b26e8fb9078211287c9c7734c3

Contents?: true

Size: 1.18 KB

Versions: 8

Compression:

Stored size: 1.18 KB

Contents

# frozen_string_literal: true

require 'bolt/error'

# Deep merges a hash of facts with the existing facts on a target.
#
# **NOTE:** Not available in apply block
Puppet::Functions.create_function(:add_facts) do
  # @param target A target.
  # @param facts A hash of fact names to values that may include structured facts.
  # @return The target's new facts.
  # @example Adding facts to a target
  #   add_facts($target, { 'os' => { 'family' => 'windows', 'name' => 'windows' } })
  dispatch :add_facts do
    param 'Target', :target
    param 'Hash', :facts
    return_type 'Hash[String, Data]'
  end

  def add_facts(target, facts)
    unless Puppet[:tasks]
      raise Puppet::ParseErrorWithIssue
        .from_issue_and_stack(Bolt::PAL::Issues::PLAN_OPERATION_NOT_SUPPORTED_WHEN_COMPILING, action: 'add_facts')
    end

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

    unless inventory
      raise Puppet::ParseErrorWithIssue.from_issue_and_stack(
        Puppet::Pops::Issues::TASK_MISSING_BOLT, action: _('add facts')
      )
    end

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

    inventory.add_facts(target, facts)
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
bolt-1.19.0 bolt-modules/boltlib/lib/puppet/functions/add_facts.rb
bolt-1.18.0 bolt-modules/boltlib/lib/puppet/functions/add_facts.rb
bolt-1.17.0 bolt-modules/boltlib/lib/puppet/functions/add_facts.rb
bolt-1.16.0 bolt-modules/boltlib/lib/puppet/functions/add_facts.rb
bolt-1.15.0 bolt-modules/boltlib/lib/puppet/functions/add_facts.rb
bolt-1.14.0 bolt-modules/boltlib/lib/puppet/functions/add_facts.rb
bolt-1.13.1 bolt-modules/boltlib/lib/puppet/functions/add_facts.rb
bolt-1.13.0 bolt-modules/boltlib/lib/puppet/functions/add_facts.rb