Sha256: b324c07268d8f714395039db3b4538b8c7c5953b03f4ba8ba90d6f7393d1f3f2

Contents?: true

Size: 1.15 KB

Versions: 26

Compression:

Stored size: 1.15 KB

Contents

# frozen_string_literal: true

require 'bolt/error'

# Deep merges a hash of facts with the existing facts on a target.
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(
        Puppet::Pops::Issues::TASK_OPERATION_NOT_SUPPORTED_WHEN_COMPILING, operation: '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

26 entries across 26 versions & 1 rubygems

Version Path
bolt-1.12.0 bolt-modules/boltlib/lib/puppet/functions/add_facts.rb
bolt-1.11.0 bolt-modules/boltlib/lib/puppet/functions/add_facts.rb
bolt-1.10.0 bolt-modules/boltlib/lib/puppet/functions/add_facts.rb
bolt-1.9.0 bolt-modules/boltlib/lib/puppet/functions/add_facts.rb
bolt-1.8.1 bolt-modules/boltlib/lib/puppet/functions/add_facts.rb
bolt-1.8.0 bolt-modules/boltlib/lib/puppet/functions/add_facts.rb
bolt-1.7.0 bolt-modules/boltlib/lib/puppet/functions/add_facts.rb
bolt-1.6.0 bolt-modules/boltlib/lib/puppet/functions/add_facts.rb
bolt-1.5.0 bolt-modules/boltlib/lib/puppet/functions/add_facts.rb
bolt-1.4.0 bolt-modules/boltlib/lib/puppet/functions/add_facts.rb
bolt-1.3.0 bolt-modules/boltlib/lib/puppet/functions/add_facts.rb
bolt-1.2.0 bolt-modules/boltlib/lib/puppet/functions/add_facts.rb
bolt-1.1.0 bolt-modules/boltlib/lib/puppet/functions/add_facts.rb
bolt-1.0.0 bolt-modules/boltlib/lib/puppet/functions/add_facts.rb
bolt-0.25.0 bolt-modules/boltlib/lib/puppet/functions/add_facts.rb
bolt-0.24.0 bolt-modules/boltlib/lib/puppet/functions/add_facts.rb
bolt-0.23.0 bolt-modules/boltlib/lib/puppet/functions/add_facts.rb
bolt-0.22.0 bolt-modules/boltlib/lib/puppet/functions/add_facts.rb
bolt-0.21.8 bolt-modules/boltlib/lib/puppet/functions/add_facts.rb
bolt-0.21.7 bolt-modules/boltlib/lib/puppet/functions/add_facts.rb