puppet-puppetdbquery
puppet-puppetdbquery copied to clipboard
How can I check if puppetdb is configured?
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.
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.
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