Skip to content

Commit c199eec

Browse files
author
Johan De Wit
committed
[Facts] remove support for version < 4.4 and use mongosh
1 parent 9f50dbc commit c199eec

File tree

1 file changed

+4
-38
lines changed

1 file changed

+4
-38
lines changed

lib/facter/is_master.rb

Lines changed: 4 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -32,43 +32,9 @@ def get_options_from_hash_config(config)
3232
result.join(' ')
3333
end
3434

35-
def get_options_from_keyvalue_config(file)
36-
config = {}
37-
File.readlines(file).map do |line|
38-
k, v = line.split('=')
39-
config[k.rstrip] = v.lstrip.chomp if k && v
40-
end
41-
42-
result = []
43-
44-
result << "--port #{config['port']}" unless config['port'].nil?
45-
# use --ssl and --host if:
46-
# - sslMode is "requireSSL"
47-
# - Parameter --sslPEMKeyFile is set
48-
# - Parameter --sslCAFile is set
49-
result << "--ssl --host #{Facter.value(:fqdn)}" if config['ssl'] == 'requireSSL' || !config['sslcert'].nil? || !config['sslca'].nil?
50-
result << "--sslPEMKeyFile #{config['sslcert']}" unless config['sslcert'].nil?
51-
result << "--sslCAFile #{config['sslca']}" unless config['sslca'].nil?
52-
# use --tls and --host if:
53-
# - tlsMode is "requireTLS"
54-
# - Parameter --tlsCertificateKeyFile is set
55-
# - Parameter --tlsCAFile is set
56-
result << "--tls --host #{Facter.value(:fqdn)}" if config['tls'] == 'requireTLS' || !config['tlscert'].nil? || !config['tlsca'].nil?
57-
result << "--tlsCertificateKeyFile #{config['tlscert']}" unless config['tlscert'].nil?
58-
result << "--tlsCAFile #{config['tlsca']}" unless config['tlsca'].nil?
59-
60-
result << '--ipv6' unless config['ipv6'].nil?
61-
62-
result.join(' ')
63-
end
64-
6535
def get_options_from_config(file)
6636
config = YAML.load_file(file)
67-
if config.is_a?(Hash) # Using a valid YAML file for mongo 2.6
68-
get_options_from_hash_config(config)
69-
else # It has to be a key-value config file
70-
get_options_from_keyvalue_config(file)
71-
end
37+
get_options_from_hash_config(config)
7238
end
7339

7440
Facter.add('mongodb_is_master') do
@@ -77,13 +43,13 @@ def get_options_from_config(file)
7743
file = mongod_conf_file
7844
if file
7945
options = get_options_from_config(file)
80-
e = File.exist?('/root/.mongorc.js') ? 'load(\'/root/.mongorc.js\'); ' : ''
46+
e = File.exist?('/root/.mongoshrc.js') ? 'load(\'/root/.mongoshrc.js\'); ' : ''
8147

8248
# Check if the mongodb server is responding:
83-
Facter::Core::Execution.exec("mongo --quiet #{options} --eval \"#{e}printjson(db.adminCommand({ ping: 1 }))\"")
49+
Facter::Core::Execution.exec("mongosh --quiet #{options} --eval \"#{e}printjson(db.adminCommand({ ping: 1 }))\"")
8450

8551
if $CHILD_STATUS.success?
86-
Facter::Core::Execution.exec("mongo --quiet #{options} --eval \"#{e}db.isMaster().ismaster\"")
52+
Facter::Core::Execution.exec("mongosh --quiet #{options} --eval \"#{e}db.isMaster().ismaster\"")
8753
else
8854
'not_responding'
8955
end

0 commit comments

Comments
 (0)