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.22.1 bolt-modules/boltlib/lib/puppet/functions/puppetdb_fact.rb
bolt-3.22.0 bolt-modules/boltlib/lib/puppet/functions/puppetdb_fact.rb
bolt-3.21.0 bolt-modules/boltlib/lib/puppet/functions/puppetdb_fact.rb
bolt-3.20.0 bolt-modules/boltlib/lib/puppet/functions/puppetdb_fact.rb
bolt-3.19.0 bolt-modules/boltlib/lib/puppet/functions/puppetdb_fact.rb
bolt-3.18.0 bolt-modules/boltlib/lib/puppet/functions/puppetdb_fact.rb
bolt-3.17.0 bolt-modules/boltlib/lib/puppet/functions/puppetdb_fact.rb
bolt-3.16.1 bolt-modules/boltlib/lib/puppet/functions/puppetdb_fact.rb
bolt-3.16.0 bolt-modules/boltlib/lib/puppet/functions/puppetdb_fact.rb
bolt-3.15.0 bolt-modules/boltlib/lib/puppet/functions/puppetdb_fact.rb
bolt-3.14.1 bolt-modules/boltlib/lib/puppet/functions/puppetdb_fact.rb
bolt-3.13.0 bolt-modules/boltlib/lib/puppet/functions/puppetdb_fact.rb
bolt-3.12.0 bolt-modules/boltlib/lib/puppet/functions/puppetdb_fact.rb
bolt-3.11.0 bolt-modules/boltlib/lib/puppet/functions/puppetdb_fact.rb
bolt-3.10.0 bolt-modules/boltlib/lib/puppet/functions/puppetdb_fact.rb
bolt-3.9.2 bolt-modules/boltlib/lib/puppet/functions/puppetdb_fact.rb
bolt-3.9.1 bolt-modules/boltlib/lib/puppet/functions/puppetdb_fact.rb
bolt-3.9.0 bolt-modules/boltlib/lib/puppet/functions/puppetdb_fact.rb
bolt-3.8.1 bolt-modules/boltlib/lib/puppet/functions/puppetdb_fact.rb
bolt-3.8.0 bolt-modules/boltlib/lib/puppet/functions/puppetdb_fact.rb