Sha256: 346ec6199d1991d527ea1b75a35a8c09e696b34c9b8e2aed6a4cd4c95a9406f4

Contents?: true

Size: 1.08 KB

Versions: 41

Compression:

Stored size: 1.08 KB

Contents

# frozen_string_literal: true

require 'bolt/error'

# Makes a query to [puppetdb](https://puppet.com/docs/puppetdb/latest/index.html)
# using Bolt's PuppetDB client.
Puppet::Functions.create_function(:puppetdb_query) do
  # rubocop:disable Layout/LineLength
  # @param query A PQL query.
  #   Learn more about [Puppet's query language](https://puppet.com/docs/puppetdb/latest/api/query/tutorial-pql.html), PQL.
  # @return Results of the PuppetDB query.
  # @example Request certnames for all nodes
  #   puppetdb_query('nodes[certname] {}')
  # rubocop:enable Layout/LineLength
  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)
    # 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.make_query(query)
  end
end

Version data entries

41 entries across 41 versions & 1 rubygems

Version Path
bolt-3.22.1 bolt-modules/boltlib/lib/puppet/functions/puppetdb_query.rb
bolt-3.22.0 bolt-modules/boltlib/lib/puppet/functions/puppetdb_query.rb
bolt-3.21.0 bolt-modules/boltlib/lib/puppet/functions/puppetdb_query.rb
bolt-3.20.0 bolt-modules/boltlib/lib/puppet/functions/puppetdb_query.rb
bolt-3.19.0 bolt-modules/boltlib/lib/puppet/functions/puppetdb_query.rb
bolt-3.18.0 bolt-modules/boltlib/lib/puppet/functions/puppetdb_query.rb
bolt-3.17.0 bolt-modules/boltlib/lib/puppet/functions/puppetdb_query.rb
bolt-3.16.1 bolt-modules/boltlib/lib/puppet/functions/puppetdb_query.rb
bolt-3.16.0 bolt-modules/boltlib/lib/puppet/functions/puppetdb_query.rb
bolt-3.15.0 bolt-modules/boltlib/lib/puppet/functions/puppetdb_query.rb
bolt-3.14.1 bolt-modules/boltlib/lib/puppet/functions/puppetdb_query.rb
bolt-3.13.0 bolt-modules/boltlib/lib/puppet/functions/puppetdb_query.rb
bolt-3.12.0 bolt-modules/boltlib/lib/puppet/functions/puppetdb_query.rb
bolt-3.11.0 bolt-modules/boltlib/lib/puppet/functions/puppetdb_query.rb
bolt-3.10.0 bolt-modules/boltlib/lib/puppet/functions/puppetdb_query.rb
bolt-3.9.2 bolt-modules/boltlib/lib/puppet/functions/puppetdb_query.rb
bolt-3.9.1 bolt-modules/boltlib/lib/puppet/functions/puppetdb_query.rb
bolt-3.9.0 bolt-modules/boltlib/lib/puppet/functions/puppetdb_query.rb
bolt-3.8.1 bolt-modules/boltlib/lib/puppet/functions/puppetdb_query.rb
bolt-3.8.0 bolt-modules/boltlib/lib/puppet/functions/puppetdb_query.rb