Sha256: b2c81d92f89688500bf95b177176b64f8dc3571ed7d124c14630ad201a7ee315

Contents?: true

Size: 1002 Bytes

Versions: 4

Compression:

Stored size: 1002 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 Puppet[:tasks] && puppetdb_client && Puppet.features.bolt?
      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

4 entries across 4 versions & 1 rubygems

Version Path
bolt-0.21.2 bolt-modules/boltlib/lib/puppet/functions/puppetdb_query.rb
bolt-0.21.1 bolt-modules/boltlib/lib/puppet/functions/puppetdb_query.rb
bolt-0.21.0 bolt-modules/boltlib/lib/puppet/functions/puppetdb_query.rb
bolt-0.20.7 bolt-modules/boltlib/lib/puppet/functions/puppetdb_query.rb