Sha256: e8357fe178d3fd9871d434887e3238be796cc69db9149a1829b895b40225a776

Contents?: true

Size: 959 Bytes

Versions: 8

Compression:

Stored size: 959 Bytes

Contents

# frozen_string_literal: true

require 'bolt/error'

# Makes a query to puppetdb using Bolt's PuppetDB client.
Puppet::Functions.create_function(:puppetdb_query) do
  # @param query A PQL query.
  # @return Results of the PuppetDB query.
  # @example Request certnames for all nodes
  #   puppetdb_query('nodes[certname] {}')
  dispatch :make_query do
    param 'Variant[String, Array[Data]]', :query
    return_type 'Array[Data]'
  end
  # The query type could be more specific ASTQuery = Array[Variant[String, ASTQuery]]

  def make_query(query)
    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_query')

    puppetdb_client.make_query(query)
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
bolt-0.23.0 bolt-modules/boltlib/lib/puppet/functions/puppetdb_query.rb
bolt-0.22.0 bolt-modules/boltlib/lib/puppet/functions/puppetdb_query.rb
bolt-0.21.8 bolt-modules/boltlib/lib/puppet/functions/puppetdb_query.rb
bolt-0.21.7 bolt-modules/boltlib/lib/puppet/functions/puppetdb_query.rb
bolt-0.21.6 bolt-modules/boltlib/lib/puppet/functions/puppetdb_query.rb
bolt-0.21.5 bolt-modules/boltlib/lib/puppet/functions/puppetdb_query.rb
bolt-0.21.4 bolt-modules/boltlib/lib/puppet/functions/puppetdb_query.rb
bolt-0.21.3 bolt-modules/boltlib/lib/puppet/functions/puppetdb_query.rb