1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Allow creation of Mongo user via localhost exception (#22792)

* Allow creation of user with localhost exception.

Fixes #22791

When access control is enabled, Mongo allows a user to be created from
localhost (called the "localhost exception":
https://docs.mongodb.com/v3.2/core/security-users/#localhost-exception).
When the `update_password` parameter was added to this module in
Ansible 2.1, this functionality was broken due to a query performed
before `user_add()` is called. This fix only performs the query when
when `update_password` is set to `on-create`, allowing a user to be
created via the localhost exception.

* Only set `password = None` when user exists.
This commit is contained in:
Morgan Robertson 2017-07-14 05:52:19 -04:00 committed by John R Barker
parent 640131c464
commit 44730c28cc

View file

@ -434,8 +434,9 @@ def main():
module.fail_json(msg='password parameter required when adding a user unless update_password is set to on_create') module.fail_json(msg='password parameter required when adding a user unless update_password is set to on_create')
try: try:
if update_password != 'always':
uinfo = user_find(client, user, db_name) uinfo = user_find(client, user, db_name)
if update_password != 'always' and uinfo: if uinfo:
password = None password = None
if not check_if_roles_changed(uinfo, roles, db_name): if not check_if_roles_changed(uinfo, roles, db_name):
module.exit_json(changed=False, user=user) module.exit_json(changed=False, user=user)