Sha256: 336d704cc25199eea49b68ceaa18134022e72a08f7d6187c8eaae4fc160c5c2e

Contents?: true

Size: 1.08 KB

Versions: 32

Compression:

Stored size: 1.08 KB

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) { nil }
    unless puppetdb_client
      raise Puppet::ParseErrorWithIssue.from_issue_and_stack(
        Puppet::Pops::Issues::TASK_MISSING_BOLT, action: _('query facts from puppetdb')
      )
    end

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

    puppetdb_client.facts_for_node(certnames)
  end
end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
bolt-1.19.0 bolt-modules/boltlib/lib/puppet/functions/puppetdb_fact.rb
bolt-1.18.0 bolt-modules/boltlib/lib/puppet/functions/puppetdb_fact.rb
bolt-1.17.0 bolt-modules/boltlib/lib/puppet/functions/puppetdb_fact.rb
bolt-1.16.0 bolt-modules/boltlib/lib/puppet/functions/puppetdb_fact.rb
bolt-1.15.0 bolt-modules/boltlib/lib/puppet/functions/puppetdb_fact.rb
bolt-1.14.0 bolt-modules/boltlib/lib/puppet/functions/puppetdb_fact.rb
bolt-1.13.1 bolt-modules/boltlib/lib/puppet/functions/puppetdb_fact.rb
bolt-1.13.0 bolt-modules/boltlib/lib/puppet/functions/puppetdb_fact.rb
bolt-1.12.0 bolt-modules/boltlib/lib/puppet/functions/puppetdb_fact.rb
bolt-1.11.0 bolt-modules/boltlib/lib/puppet/functions/puppetdb_fact.rb
bolt-1.10.0 bolt-modules/boltlib/lib/puppet/functions/puppetdb_fact.rb
bolt-1.9.0 bolt-modules/boltlib/lib/puppet/functions/puppetdb_fact.rb
bolt-1.8.1 bolt-modules/boltlib/lib/puppet/functions/puppetdb_fact.rb
bolt-1.8.0 bolt-modules/boltlib/lib/puppet/functions/puppetdb_fact.rb
bolt-1.7.0 bolt-modules/boltlib/lib/puppet/functions/puppetdb_fact.rb
bolt-1.6.0 bolt-modules/boltlib/lib/puppet/functions/puppetdb_fact.rb
bolt-1.5.0 bolt-modules/boltlib/lib/puppet/functions/puppetdb_fact.rb
bolt-1.4.0 bolt-modules/boltlib/lib/puppet/functions/puppetdb_fact.rb
bolt-1.3.0 bolt-modules/boltlib/lib/puppet/functions/puppetdb_fact.rb
bolt-1.2.0 bolt-modules/boltlib/lib/puppet/functions/puppetdb_fact.rb