148
148
# MongoDB module specific support methods.
149
149
#
150
150
151
+ def check_compatibility (module , client ):
152
+ srv_info = client .server_info ()
153
+ if LooseVersion (srv_info ['version' ]) >= LooseVersion ('3.0' ) and LooseVersion (PyMongoVersion ) <= LooseVersion ('3.0' ):
154
+ module .fail_json (msg = ' (Note: you must use pymongo 3.0+ with MongoDB >= 3.0)' )
155
+ elif LooseVersion (srv_info ['version' ]) >= LooseVersion ('2.6' ) and LooseVersion (PyMongoVersion ) <= LooseVersion ('2.7' ):
156
+ module .fail_json (msg = ' (Note: you must use pymongo 2.7.x-2.9.x with MongoDB 2.6)' )
157
+ elif LooseVersion (PyMongoVersion ) <= LooseVersion ('2.5' ):
158
+ module .fail_json (msg = ' (Note: you must be on mongodb 2.4+ and pymongo 2.5+ to use the roles param)' )
159
+
151
160
def user_find (client , user ):
152
161
for mongo_user in client ["admin" ].system .users .find ():
153
162
if mongo_user ['user' ] == user :
@@ -165,13 +174,6 @@ def user_add(module, client, db_name, user, password, roles):
165
174
db .add_user (user , password , None , roles = roles )
166
175
except OperationFailure , e :
167
176
err_msg = str (e )
168
- srv_info = client .server_info ()
169
- if LooseVersion (srv_info ['version' ]) >= LooseVersion ('3.0' ) and LooseVersion (PyMongoVersion ) <= LooseVersion ('3.0' ):
170
- err_msg = err_msg + ' (Note: you must use pymongo 3.0+ with MongoDB >= 3.0)'
171
- elif LooseVersion (srv_info ['version' ]) >= LooseVersion ('2.6' ) and LooseVersion (PyMongoVersion ) <= LooseVersion ('2.7' ):
172
- err_msg = err_msg + ' (Note: you must use pymongo 2.7.x-2.9.x with MongoDB 2.6)'
173
- elif LooseVersion (PyMongoVersion ) <= LooseVersion ('2.5' ):
174
- err_msg = err_msg + ' (Note: you must be on mongodb 2.4+ and pymongo 2.5+ to use the roles param)'
175
177
module .fail_json (msg = err_msg )
176
178
177
179
def user_remove (module , client , db_name , user ):
@@ -262,6 +264,8 @@ def main():
262
264
except ConnectionFailure , e :
263
265
module .fail_json (msg = 'unable to connect to database: %s' % str (e ))
264
266
267
+ check_compatibility (module , client )
268
+
265
269
if state == 'present' :
266
270
if password is None and update_password == 'always' :
267
271
module .fail_json (msg = 'password parameter required when adding a user unless update_password is set to on_create' )
0 commit comments