146
146
# =========================================
147
147
# MongoDB module specific support methods.
148
148
#
149
+ def check_compatibility (module , client ):
150
+ srv_info = client .server_info ()
151
+ if LooseVersion (srv_info ['version' ]) >= LooseVersion ('3.0' ) and LooseVersion (PyMongoVersion ) <= LooseVersion ('3.0' ):
152
+ module .fail_json (msg = ' (Note: you must use pymongo 3.0+ with MongoDB >= 3.0)' )
153
+ elif LooseVersion (srv_info ['version' ]) >= LooseVersion ('2.6' ) and LooseVersion (PyMongoVersion ) <= LooseVersion ('2.7' ):
154
+ module .fail_json (msg = ' (Note: you must use pymongo 2.7.x-2.9.x with MongoDB 2.6)' )
155
+ elif LooseVersion (PyMongoVersion ) <= LooseVersion ('2.5' ):
156
+ module .fail_json (msg = ' (Note: you must be on mongodb 2.4+ and pymongo 2.5+ to use the roles param)' )
149
157
150
158
def check_members (state , module , client , host_name , host_port , host_type ):
151
159
admin_db = client ['admin' ]
@@ -331,6 +339,7 @@ def main():
331
339
module .fail_json (msg = 'replica_set parameter is required' )
332
340
else :
333
341
client = MongoReplicaSetClient (login_host , int (login_port ), replicaSet = replica_set , ssl = ssl )
342
+ check_compatibility (module , client )
334
343
335
344
authenticate (client , login_user , login_password )
336
345
@@ -339,6 +348,7 @@ def main():
339
348
except ConfigurationError :
340
349
try :
341
350
client = MongoClient (login_host , int (login_port ), ssl = ssl )
351
+ check_compatibility (module , client )
342
352
authenticate (client , login_user , login_password )
343
353
if state == 'present' :
344
354
new_host = { '_id' : 0 , 'host' : "{0}:{1}" .format (host_name , host_port ) }
0 commit comments