Skip to content

Commit

Permalink
re-add idempotency check
Browse files Browse the repository at this point in the history
  • Loading branch information
cove committed Apr 5, 2014
1 parent 6e81f41 commit 6a321fe
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions library/database/mongodb_user
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 6a321fe

Please sign in to comment.