Skip to content

Commit

Permalink
Merge pull request #245 from fatmcgav/add_facts
Browse files Browse the repository at this point in the history
Add mongodb_is_master fact.
  • Loading branch information
hunner committed Mar 11, 2016
2 parents d6141b5 + 35190a4 commit d149aca
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/facter/is_master.rb
@@ -0,0 +1,12 @@
require 'json';

Facter.add('mongodb_is_master') do
setcode do
if Facter::Core::Execution.which('mongo')
mongo_output = Facter::Core::Execution.exec('mongo --quiet --eval "load(\'/root/.mongorc.js\'); printjson(db.isMaster())"')
JSON.parse(mongo_output.gsub(/ISODate\((.+?)\)/, '\1 '))['ismaster'] ||= false
else
'not_installed'
end
end
end

0 comments on commit d149aca

Please sign in to comment.