diff --git a/lib/ansible/modules/database/mongodb/mongodb_shard.py b/lib/ansible/modules/database/mongodb/mongodb_shard.py index 0a7973d3a44..8dc67b1690a 100644 --- a/lib/ansible/modules/database/mongodb/mongodb_shard.py +++ b/lib/ansible/modules/database/mongodb/mongodb_shard.py @@ -289,7 +289,7 @@ def main(): try: client['admin'].command('listDatabases', 1.0) # if this throws an error we need to authenticate except Exception as excep: - if "not authorized on" in str(excep): + if "not authorized on" in str(excep) or "command listDatabases requires authentication" in str(excep): if login_user is not None and login_password is not None: client.admin.authenticate(login_user, login_password, source=login_database) else: