Sha256: f96e2a3fd4974334df3508554de4bea72dba280c06f90716c8245971c6975d5a

Contents?: true

Size: 967 Bytes

Versions: 31

Compression:

Stored size: 967 Bytes

Contents

# frozen_string_literal: true

require 'bolt/error'

# Collects facts based on a list of certnames.
#
# * If a node is not found in PuppetDB, it's included in the returned hash with empty facts hash.
# * Otherwise the node is included in the hash with a value that is a hash of it's facts.
Puppet::Functions.create_function(:puppetdb_fact) do
  # @param certnames Array of certnames.
  # @return A hash of certname to facts hash for each matched Target.
  # @example Get facts for nodes
  #   puppetdb_fact(['app.example.com', 'db.example.com'])
  dispatch :puppetdb_fact do
    param 'Array[String]', :certnames
    return_type 'Hash[String, Data]'
  end

  def puppetdb_fact(certnames)
    puppetdb_client = Puppet.lookup(:bolt_pdb_client)
    # Bolt executor not expected when invoked from apply block
    executor = Puppet.lookup(:bolt_executor) { nil }
    executor&.report_function_call(self.class.name)

    puppetdb_client.facts_for_node(certnames)
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
bolt-1.49.0 bolt-modules/boltlib/lib/puppet/functions/puppetdb_fact.rb
bolt-1.48.0 bolt-modules/boltlib/lib/puppet/functions/puppetdb_fact.rb
bolt-1.47.0 bolt-modules/boltlib/lib/puppet/functions/puppetdb_fact.rb
bolt-1.45.0 bolt-modules/boltlib/lib/puppet/functions/puppetdb_fact.rb
bolt-1.44.0 bolt-modules/boltlib/lib/puppet/functions/puppetdb_fact.rb
bolt-1.43.0 bolt-modules/boltlib/lib/puppet/functions/puppetdb_fact.rb
bolt-1.42.0 bolt-modules/boltlib/lib/puppet/functions/puppetdb_fact.rb
bolt-1.41.0 bolt-modules/boltlib/lib/puppet/functions/puppetdb_fact.rb
bolt-1.40.0 bolt-modules/boltlib/lib/puppet/functions/puppetdb_fact.rb
bolt-1.39.0 bolt-modules/boltlib/lib/puppet/functions/puppetdb_fact.rb
bolt-1.38.0 bolt-modules/boltlib/lib/puppet/functions/puppetdb_fact.rb
bolt-1.37.0 bolt-modules/boltlib/lib/puppet/functions/puppetdb_fact.rb
bolt-1.36.0 bolt-modules/boltlib/lib/puppet/functions/puppetdb_fact.rb
bolt-1.35.0 bolt-modules/boltlib/lib/puppet/functions/puppetdb_fact.rb
bolt-1.34.0 bolt-modules/boltlib/lib/puppet/functions/puppetdb_fact.rb
bolt-1.33.0 bolt-modules/boltlib/lib/puppet/functions/puppetdb_fact.rb
bolt-1.32.0 bolt-modules/boltlib/lib/puppet/functions/puppetdb_fact.rb
bolt-1.31.1 bolt-modules/boltlib/lib/puppet/functions/puppetdb_fact.rb
bolt-1.31.0 bolt-modules/boltlib/lib/puppet/functions/puppetdb_fact.rb
bolt-1.30.1 bolt-modules/boltlib/lib/puppet/functions/puppetdb_fact.rb