From ae0721d3dade79e1c7e220513aa5f3e8abdac966 Mon Sep 17 00:00:00 2001 From: Cove Schneider Date: Sat, 5 Apr 2014 16:31:33 -0700 Subject: [PATCH] re-add idempotency check --- database/mongodb_user | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/database/mongodb_user b/database/mongodb_user index 2858919c485..5d7e0897b68 100644 --- a/database/mongodb_user +++ b/database/mongodb_user @@ -48,6 +48,7 @@ options: required: false default: 27017 replica_set: + version_added: "1.6" description: - Replica set to connect to (automatically connects to primary for writes) required: false @@ -196,6 +197,15 @@ def main(): else: client = MongoClient(login_host, int(login_port)) + # try to authenticate as a target user to check if it already exists + try: + client[db_name].authenticate(user, password) + if state == 'present': + module.exit_json(changed=False, user=user) + except OperationFailure: + if state == 'absent': + module.exit_json(changed=False, user=user) + if login_user is None and login_password is None: mongocnf_creds = load_mongocnf() if mongocnf_creds is not False: