{"action":"created","issue":{"url":"https://api.github.com/repos/dalen/puppet-puppetdbquery/issues/83","repository_url":"https://api.github.com/repos/dalen/puppet-puppetdbquery","labels_url":"https://api.github.com/repos/dalen/puppet-puppetdbquery/issues/83/labels{/name}","comments_url":"https://api.github.com/repos/dalen/puppet-puppetdbquery/issues/83/comments","events_url":"https://api.github.com/repos/dalen/puppet-puppetdbquery/issues/83/events","html_url":"https://github.com/dalen/puppet-puppetdbquery/issues/83","id":129707912,"number":83,"title":"How can I check if puppetdb is configured?","user":{"login":"cristifalcas","id":3647635,"avatar_url":"https://avatars.githubusercontent.com/u/3647635?v=3","gravatar_id":"","url":"https://api.github.com/users/cristifalcas","html_url":"https://github.com/cristifalcas","followers_url":"https://api.github.com/users/cristifalcas/followers","following_url":"https://api.github.com/users/cristifalcas/following{/other_user}","gists_url":"https://api.github.com/users/cristifalcas/gists{/gist_id}","starred_url":"https://api.github.com/users/cristifalcas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cristifalcas/subscriptions","organizations_url":"https://api.github.com/users/cristifalcas/orgs","repos_url":"https://api.github.com/users/cristifalcas/repos","events_url":"https://api.github.com/users/cristifalcas/events{/privacy}","received_events_url":"https://api.github.com/users/cristifalcas/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-01-29T09:03:39Z","updated_at":"2016-11-10T12:01:02Z","closed_at":null,"body":"When bootstrapping a completely new puppet system, we get an error from this module:\n\nError: Could not run: cannot load such file -- puppet/util/puppetdb\n\nThis is because at that moment nothing is configured/installed (also no puppetdb server).\n\nWe are trying to do the initial configuration for the puppet master by using puppet apply.\n\nIs there any possibility to do a check for this case?\n\nI'm not sure I'm making any sense, so please tell me if it's not clear what my problem is.\n"},"comment":{"url":"https://api.github.com/repos/dalen/puppet-puppetdbquery/issues/comments/259672990","html_url":"https://github.com/dalen/puppet-puppetdbquery/issues/83#issuecomment-259672990","issue_url":"https://api.github.com/repos/dalen/puppet-puppetdbquery/issues/83","id":259672990,"user":{"login":"fondemen","id":621289,"avatar_url":"https://avatars.githubusercontent.com/u/621289?v=3","gravatar_id":"","url":"https://api.github.com/users/fondemen","html_url":"https://github.com/fondemen","followers_url":"https://api.github.com/users/fondemen/followers","following_url":"https://api.github.com/users/fondemen/following{/other_user}","gists_url":"https://api.github.com/users/fondemen/gists{/gist_id}","starred_url":"https://api.github.com/users/fondemen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fondemen/subscriptions","organizations_url":"https://api.github.com/users/fondemen/orgs","repos_url":"https://api.github.com/users/fondemen/repos","events_url":"https://api.github.com/users/fondemen/events{/privacy}","received_events_url":"https://api.github.com/users/fondemen/received_events","type":"User","site_admin":false},"created_at":"2016-11-10T12:01:02Z","updated_at":"2016-11-10T12:01:02Z","body":"Hello,\r\n\r\nI was able to workaround this issue by adding a fact that mimcs this module checks:\r\n\r\n``` ruby\r\nFacter.add('puppetdb_running') do\r\n  setcode do\r\n  \r\n    begin\r\n      require 'puppet/util/puppetdb'\r\n    \r\n      # This is needed if the puppetdb library isn't pluginsynced to the master\r\n      $LOAD_PATH.unshift File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..'))\r\n      begin\r\n        require 'puppetdb/connection'\r\n      ensure\r\n        $LOAD_PATH.shift\r\n      end\r\n      \r\n      PuppetDB::Connection.check_version\r\n      true\r\n    rescue => e\r\n      # puts e.message\r\n      # puts e.backtrace\r\n      false\r\n    end\r\n  end\r\nend\r\n```\r\n\r\nand then in my puppet code:\r\n\r\n``` puppet\r\nif $::puppetdb_running {\r\n\t  $nodes = query_nodes('friendly')\r\n} else {\r\n    $nodes = []\r\n}\r\n```\r\n\r\nNevertheless, if quixoten's answer is more elegant, it would be great if this module could offer such variable natively...\r\n\r\nRegards\r\n\r\nFrédéric"}}
{"actor":{"display_login":"fondemen"}}