{"id":1258,"date":"2010-01-14T19:47:01","date_gmt":"2010-01-14T18:47:01","guid":{"rendered":"http:\/\/www.devco.net\/?p=1258"},"modified":"2010-06-27T19:19:07","modified_gmt":"2010-06-27T18:19:07","slug":"better_way_to_query_facts","status":"publish","type":"post","link":"https:\/\/www.devco.net\/archives\/2010\/01\/14\/better_way_to_query_facts.php","title":{"rendered":"Better way to query facts"},"content":{"rendered":"

Facter has some annoying bug where it won’t always print all facts when called like facter fact<\/em>, ones that require dynamic lookups etc just won’t print.<\/p>\n

This is a long standing bug that doesn’t seem to get any love, so I hacked up a little wrapper that works better.<\/p>\n

<\/p>\n

\r\n#!\/usr\/bin\/ruby\r\n\r\nrequire 'facter'\r\nrequire 'puppet'\r\n\r\nPuppet.parse_config\r\nunless $LOAD_PATH.include?(Puppet[:libdir])\r\n    $LOAD_PATH << Puppet[:libdir]\r\nend\r\n\r\nfacts = Facter.to_hash\r\n\r\nif ARGV.size > 0\r\n    ARGV.each do |f|\r\n        puts \"#{f} => #{facts[f]}\" if facts.include?(f)\r\n    end\r\nelse\r\n    facts.each_pair do |k,v|\r\n        puts(\"#{k} => #{v}\")\r\n    end\r\nend\r\n<\/pre>\n

<\/code><\/p>\n

It behaves by default as if you ran facter -p<\/em> but you can supply as many fact names as you want on the command line to print just the ones requested.<\/p>\n

<\/p>\n

\r\n$ fctr uptime puppetversion processorcount\r\nuptime => 8 days\r\npuppetversion => 0.25.2\r\nprocessorcount => 1\r\n<\/pre>\n

<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"

Facter has some annoying bug where it won’t always print all facts when called like facter fact, ones that require dynamic lookups etc just won’t print. This is a long standing bug that doesn’t seem to get any love, so I hacked up a little wrapper that works better. #!\/usr\/bin\/ruby require ‘facter’ require ‘puppet’ Puppet.parse_config […]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","footnotes":""},"categories":[7],"tags":[121,21,13],"_links":{"self":[{"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/posts\/1258"}],"collection":[{"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/comments?post=1258"}],"version-history":[{"count":5,"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/posts\/1258\/revisions"}],"predecessor-version":[{"id":1520,"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/posts\/1258\/revisions\/1520"}],"wp:attachment":[{"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/media?parent=1258"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/categories?post=1258"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/tags?post=1258"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}