fix #1747 mongodb_user support check mode

reviewable/pr18780/r1
Guillaume Dufour 9 years ago
parent fade5b7936
commit 8c3aeac4a3

@ -172,6 +172,8 @@ def user_add(module, client, db_name, user, password, roles):
def user_remove(module, client, db_name, user): def user_remove(module, client, db_name, user):
exists = user_find(client, user) exists = user_find(client, user)
if exists: if exists:
if module.check_mode:
module.exit_json(changed=True, user=user)
db = client[db_name] db = client[db_name]
db.remove_user(user) db.remove_user(user)
else: else:
@ -212,7 +214,8 @@ def main():
roles=dict(default=None, type='list'), roles=dict(default=None, type='list'),
state=dict(default='present', choices=['absent', 'present']), state=dict(default='present', choices=['absent', 'present']),
update_password=dict(default="always", choices=["always", "on_create"]), update_password=dict(default="always", choices=["always", "on_create"]),
) ),
supports_check_mode=True
) )
if not pymongo_found: if not pymongo_found:
@ -264,6 +267,9 @@ def main():
if update_password != 'always' and user_find(client, user): if update_password != 'always' and user_find(client, user):
password = None password = None
if module.check_mode:
module.exit_json(changed=True, user=user)
try: try:
user_add(module, client, db_name, user, password, roles) user_add(module, client, db_name, user, password, roles)
except OperationFailure, e: except OperationFailure, e:

Loading…
Cancel
Save