Sha256: a3abc54d5a1b95dcd295394ccbd1a48d454caec217ea32df2ea46e0dbcdb15a9

Contents?: true

Size: 1.18 KB

Versions: 24

Compression:

Stored size: 1.18 KB

Contents

# frozen_string_literal: true

require 'bolt/error'

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

24 entries across 24 versions & 1 rubygems

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