Skip to content

Commit 991af66

Browse files
committed
Handle non-existing config file
When using the RH MongoDB 3.4 SCL the config file is in /etc/opt/rh/rh-mongodb34/mongod.conf which causes this fact to fail because the -syspaths package still installs the binaries to /usr/bin. Since we don't use this fact, it's enough for now to gracefully handle this. Ideally we could use the value for mongodb::server::config but I'm not aware of a way to do this in facts.
1 parent 90fc82a commit 991af66

1 file changed

Lines changed: 13 additions & 13 deletions

File tree

lib/facter/is_master.rb

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,8 @@
22
require 'yaml'
33

44
def mongod_conf_file
5-
file = if File.exist? '/etc/mongod.conf'
6-
'/etc/mongod.conf'
7-
else
8-
'/etc/mongodb.conf'
9-
end
10-
file
5+
locations = ['/etc/mongod.conf', '/etc/mongodb.conf']
6+
locations.find { |location| File.exist? location }
117
end
128

139
def get_options_from_hash_config(config)
@@ -53,16 +49,20 @@ def get_options_from_config(file)
5349
setcode do
5450
if %w[mongo mongod].all? { |m| Facter::Util::Resolution.which m }
5551
file = mongod_conf_file
56-
options = get_config_options(file)
57-
e = File.exist?('/root/.mongorc.js') ? 'load(\'/root/.mongorc.js\'); ' : ''
52+
if file
53+
options = get_config_options(file)
54+
e = File.exist?('/root/.mongorc.js') ? 'load(\'/root/.mongorc.js\'); ' : ''
5855

59-
# Check if the mongodb server is responding:
60-
Facter::Core::Execution.exec("mongo --quiet #{options} --eval \"#{e}printjson(db.adminCommand({ ping: 1 }))\"")
56+
# Check if the mongodb server is responding:
57+
Facter::Core::Execution.exec("mongo --quiet #{options} --eval \"#{e}printjson(db.adminCommand({ ping: 1 }))\"")
6158

62-
if $CHILD_STATUS.success?
63-
Facter::Core::Execution.exec("mongo --quiet #{options} --eval \"#{e}db.isMaster().ismaster\"")
59+
if $CHILD_STATUS.success?
60+
Facter::Core::Execution.exec("mongo --quiet #{options} --eval \"#{e}db.isMaster().ismaster\"")
61+
else
62+
'not_responding'
63+
end
6464
else
65-
'not_responding'
65+
'not_configured'
6666
end
6767
else
6868
'not_installed'

0 commit comments

Comments
 (0)