ansible/ansible — pull request #5597 by laggyluke (2014-01-13 14:04:44+00:00)
Title: Add idempotency to mongodb_user module

This patch adds an extra login attempt to find out if a given user already exists and exits early if `state` condition is met.

Before this patch, `mongodb_user` module always reported `changed=True` and tried to create a user, even if a given user was already present in the database.

Previous behaviour also creates sort of a chicken-and-egg problem when you want to create your first admin user:
* if you specify login_user and login_password, it will fail at the first time because no users exist in the database yet.
* if you don't specify login_user and login_password (and rely on MongoDB's [localhost exception](http://docs.mongodb.org/manual/tutorial/add-user-administrator/#localhost-exception)), then it will succeed on the first run, but will fail on any subsequent run, because there is already a user in the database, so localhost exception doesn't kick in and login_user/login_password are required.

I don't see any obvious backward incompatibilities, unless someone relied on this buggy behaviour - in that case we can hide it behind an extra `precheck_credentials` flag parameter or something like that.