summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTHEBAULT Julien <julien@thebault.co>2016-09-27 16:05:54 +0200
committerRené Moser <mail@renemoser.net>2016-09-29 07:16:30 +0200
commit085321e3a879575340ad83b4169606a6139d75ce (patch)
tree196e5f60af547f648063f5c37cb647d2bd076ed1
parent48e55c9d7a772b14d436ae0e4fda53da6a164ddb (diff)
downloadansible-085321e3a879575340ad83b4169606a6139d75ce.tar.gz
Fix mongodb user compatibility check (#2731)
- Check the compatibility asap
-rw-r--r--database/misc/mongodb_user.py27
1 files changed, 21 insertions, 6 deletions
diff --git a/database/misc/mongodb_user.py b/database/misc/mongodb_user.py
index 3f391a7e94..33187b35b9 100644
--- a/database/misc/mongodb_user.py
+++ b/database/misc/mongodb_user.py
@@ -174,13 +174,26 @@ else:
#
def check_compatibility(module, client):
- srv_info = client.server_info()
- if LooseVersion(srv_info['version']) >= LooseVersion('3.2') and LooseVersion(PyMongoVersion) <= LooseVersion('3.2'):
+ """Check the compatibility between the driver and the database.
+
+ See: https://docs.mongodb.com/ecosystem/drivers/driver-compatibility-reference/#python-driver-compatibility
+
+ Args:
+ module: Ansible module.
+ client (cursor): Mongodb cursor on admin database.
+ """
+ loose_srv_version = LooseVersion(client.server_info()['version'])
+ loose_driver_version = LooseVersion(PyMongoVersion)
+
+ if loose_srv_version >= LooseVersion('3.2') and loose_driver_version <= LooseVersion('3.2'):
module.fail_json(msg=' (Note: you must use pymongo 3.2+ with MongoDB >= 3.2)')
- elif LooseVersion(srv_info['version']) >= LooseVersion('3.0') and LooseVersion(PyMongoVersion) <= LooseVersion('2.8'):
+
+ elif loose_srv_version >= LooseVersion('3.0') and loose_driver_version <= LooseVersion('2.8'):
module.fail_json(msg=' (Note: you must use pymongo 2.8+ with MongoDB 3.0)')
- elif LooseVersion(srv_info['version']) >= LooseVersion('2.6') and LooseVersion(PyMongoVersion) <= LooseVersion('2.7'):
+
+ elif loose_srv_version >= LooseVersion('2.6') and loose_srv_version <= LooseVersion('2.7'):
module.fail_json(msg=' (Note: you must use pymongo 2.7+ with MongoDB 2.6)')
+
elif LooseVersion(PyMongoVersion) <= LooseVersion('2.5'):
module.fail_json(msg=' (Note: you must be on mongodb 2.4+ and pymongo 2.5+ to use the roles param)')
@@ -339,6 +352,10 @@ def main():
client = MongoClient(**connection_params)
+ # NOTE: this check must be done ASAP.
+ # We doesn't need to be authenticated.
+ check_compatibility(module, client)
+
if login_user is None and login_password is None:
mongocnf_creds = load_mongocnf()
if mongocnf_creds is not False:
@@ -357,8 +374,6 @@ def main():
except Exception, e:
module.fail_json(msg='unable to connect to database: %s' % str(e))
- check_compatibility(module, client)
-
if state == 'present':
if password is None and update_password == 'always':
module.fail_json(msg='password parameter required when adding a user unless update_password is set to on_create')