Skip to content

Commit 35190a4

Browse files
committed
Add mongodb_is_master fact, which is either true or false based on db.isMaster(), or 'not_installed' if mongo isn't installed
1 parent cffc601 commit 35190a4

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)