Skip to content

Commit d149aca

Browse files
committed
Merge pull request voxpupuli#245 from fatmcgav/add_facts
Add mongodb_is_master fact.
2 parents d6141b5 + 35190a4 commit d149aca

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

lib/facter/is_master.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
require 'json';
2+
3+
Facter.add('mongodb_is_master') do
4+
setcode do
5+
if Facter::Core::Execution.which('mongo')
6+
mongo_output = Facter::Core::Execution.exec('mongo --quiet --eval "load(\'/root/.mongorc.js\'); printjson(db.isMaster())"')
7+
JSON.parse(mongo_output.gsub(/ISODate\((.+?)\)/, '\1 '))['ismaster'] ||= false
8+
else
9+
'not_installed'
10+
end
11+
end
12+
end

0 commit comments

Comments
 (0)