Merge pull request #1750 from Dufgui/mongodb_users_check_mode_1747

#1747 mongodb_user support check mode
reviewable/pr18780/r1
René Moser 9 years ago
commit d501e34694

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

Loading…
Cancel
Save