Sha256: 881ba72036f0a4cfd32ea2ff6d94b6d927db2852ddea354c714cda87f9b9db85

Contents?: true

Size: 994 Bytes

Versions: 59

Compression:

Stored size: 994 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 an empty facts hash.
# Otherwise, the node is included in the hash with a value that is a hash of its 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 }
    # Send Analytics Report
    executor&.report_function_call(self.class.name)

    puppetdb_client.facts_for_node(certnames)
  end
end

Version data entries

59 entries across 59 versions & 1 rubygems

Version Path
bolt-3.7.1 bolt-modules/boltlib/lib/puppet/functions/puppetdb_fact.rb
bolt-3.7.0 bolt-modules/boltlib/lib/puppet/functions/puppetdb_fact.rb
bolt-3.6.1 bolt-modules/boltlib/lib/puppet/functions/puppetdb_fact.rb
bolt-3.6.0 bolt-modules/boltlib/lib/puppet/functions/puppetdb_fact.rb
bolt-3.5.0 bolt-modules/boltlib/lib/puppet/functions/puppetdb_fact.rb
bolt-3.4.0 bolt-modules/boltlib/lib/puppet/functions/puppetdb_fact.rb
bolt-3.3.0 bolt-modules/boltlib/lib/puppet/functions/puppetdb_fact.rb
bolt-3.1.0 bolt-modules/boltlib/lib/puppet/functions/puppetdb_fact.rb
bolt-3.0.1 bolt-modules/boltlib/lib/puppet/functions/puppetdb_fact.rb
bolt-3.0.0 bolt-modules/boltlib/lib/puppet/functions/puppetdb_fact.rb
bolt-2.44.0 bolt-modules/boltlib/lib/puppet/functions/puppetdb_fact.rb
bolt-2.42.0 bolt-modules/boltlib/lib/puppet/functions/puppetdb_fact.rb
bolt-2.40.2 bolt-modules/boltlib/lib/puppet/functions/puppetdb_fact.rb
bolt-2.40.1 bolt-modules/boltlib/lib/puppet/functions/puppetdb_fact.rb
bolt-2.38.0 bolt-modules/boltlib/lib/puppet/functions/puppetdb_fact.rb
bolt-2.37.0 bolt-modules/boltlib/lib/puppet/functions/puppetdb_fact.rb
bolt-2.36.0 bolt-modules/boltlib/lib/puppet/functions/puppetdb_fact.rb
bolt-2.35.0 bolt-modules/boltlib/lib/puppet/functions/puppetdb_fact.rb
bolt-2.34.0 bolt-modules/boltlib/lib/puppet/functions/puppetdb_fact.rb
bolt-2.33.2 bolt-modules/boltlib/lib/puppet/functions/puppetdb_fact.rb