You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Work around authentication requirement before user creation
On the initial setup, a user doesn't yet exists so we can't
authenticate. However we require authentication. We work around this by
connecting unauthenticated using the loopback address.
Copy file name to clipboardexpand all lines: lib/puppet/provider/mongodb_replset/mongo.rb
+62-36
Original file line number
Diff line number
Diff line change
@@ -133,51 +133,70 @@ def self.replset_properties
133
133
conn_string=conn_string
134
134
begin
135
135
output=mongo_command('rs.conf()',conn_string)
136
-
rescuePuppet::ExecutionFailure
137
-
output={}
138
-
end
139
-
ifoutput['members']
140
-
return{
141
-
name: output['_id'],# replica set name
142
-
ensure: :present,
143
-
members: output['members'],
144
-
settings: output['settings'],
145
-
provider: :mongo
146
-
}
136
+
ifoutput['members']
137
+
return{
138
+
name: output['_id'],# replica set name
139
+
ensure: :present,
140
+
members: output['members'],
141
+
settings: output['settings'],
142
+
provider: :mongo
143
+
}
144
+
end
145
+
nil
146
+
rescuePuppet::ExecutionFailure=>e
147
+
ife.message =~ %r{command replSetGetConfig requires authentication} || e.message =~ %r{not authorized on admin to execute command}
148
+
output=mongo_command('rs.status()',host)
149
+
ifoutput['members']
150
+
memb=[]
151
+
output['members'].eachdo |m|
152
+
memb << {'host'=>m['name']}
153
+
end
154
+
return{
155
+
name: output['set'],
156
+
ensure: :present,
157
+
members: memb,
158
+
provider: :mongo
159
+
}
160
+
end
161
+
nil
162
+
end
147
163
end
148
-
nil
149
164
end
150
165
151
166
defget_hosts_status(members)
152
167
alive=[]
153
168
members.selectdo |member|
154
169
host=member['host']
155
170
Puppet.debug"Checking replicaset member #{host} ..."
156
-
status=rs_status(host)
157
-
raisePuppet::Error,"Can't configure replicaset #{name}, host #{host} is not supposed to be part of a replicaset."ifstatus.key?('errmsg') && status['errmsg'] == 'not running with --replSet'
Puppet.warning"Host #{host} is available, but you are unauthorized because of authentication is enabled: #{auth_enabled}"
161
-
alive.push(member)
162
-
end
163
-
164
-
ifstatus.key?('errmsg') && status['errmsg'].include?('no replset config has been received')
165
-
Puppet.debug'Mongo v4 rs.status() RS not initialized output'
166
-
alive.push(member)
167
-
end
168
-
169
-
ifstatus.key?('set')
170
-
raisePuppet::Error,"Can't configure replicaset #{name}, host #{host} is already part of another replicaset."ifstatus['set'] != name
171
-
172
-
# This node is alive and supposed to be a member of our set
173
-
Puppet.debug"Host #{host} is available for replset #{status['set']}"
174
-
alive.push(member)
175
-
elsifstatus.key?('info')
176
-
Puppet.debug"Host #{host} is alive but unconfigured: #{status['info']}"
177
-
alive.push(member)
171
+
begin
172
+
status=rs_status(host)
173
+
raisePuppet::Error,"Can't configure replicaset #{name}, host #{host} is not supposed to be part of a replicaset."ifstatus.key?('errmsg') && status['errmsg'] == 'not running with --replSet'
174
+
175
+
ifstatus.key?('set')
176
+
raisePuppet::Error,"Can't configure replicaset #{name}, host #{host} is already part of another replicaset."ifstatus['set'] != name
177
+
178
+
# This node is alive and supposed to be a member of our set
179
+
Puppet.debug"Host #{host} is available for replset #{status['set']}"
180
+
alive.push(member)
181
+
elsifstatus.key?('info')
182
+
Puppet.debug"Host #{host} is alive but unconfigured: #{status['info']}"
0 commit comments