puppet-puppetdbquery icon indicating copy to clipboard operation
puppet-puppetdbquery copied to clipboard

How can I check if puppetdb is configured?

Open cristifalcas opened this issue 9 years ago • 2 comments

When bootstrapping a completely new puppet system, we get an error from this module:

Error: Could not run: cannot load such file -- puppet/util/puppetdb

This is because at that moment nothing is configured/installed (also no puppetdb server).

We are trying to do the initial configuration for the puppet master by using puppet apply.

Is there any possibility to do a check for this case?

I'm not sure I'm making any sense, so please tell me if it's not clear what my problem is.

cristifalcas avatar Jan 29 '16 09:01 cristifalcas

Running into this issue myself. I installed the puppetdb-termini before running puppet apply, which got rid of the "cannot load such file" error, and then I put conditionals around queries that might get called during the bootstrap process, e.g.,

$friendly_nodes = $::settings::storeconfigs ? {
  true    => query_nodes('friendly'),
  default => [],
}

Not sure if that's the best thing to check, but it gets the job done. It would be awesome of this module automatically short-circuited (rather than failed) when puppet is not configured to use puppetdb.

quixoten avatar Apr 08 '16 00:04 quixoten

Hello,

I was able to workaround this issue by adding a fact that mimcs this module checks:

Facter.add('puppetdb_running') do
  setcode do

    begin
      require 'puppet/util/puppetdb'

      # This is needed if the puppetdb library isn't pluginsynced to the master
      $LOAD_PATH.unshift File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..'))
      begin
        require 'puppetdb/connection'
      ensure
        $LOAD_PATH.shift
      end

      PuppetDB::Connection.check_version
      true
    rescue => e
      # puts e.message
      # puts e.backtrace
      false
    end
  end
end

and then in my puppet code:

if $::puppetdb_running {
      $nodes = query_nodes('friendly')
} else {
    $nodes = []
}

Nevertheless, if quixoten's answer is more elegant, it would be great if this module could offer such variable natively...

Regards

Frédéric

fondemen avatar Nov 10 '16 12:11 fondemen