diff --git a/lib/ansible/modules/extras/database/misc/mongodb_user.py b/lib/ansible/modules/extras/database/misc/mongodb_user.py index 55f221981b7..f9ac1fa3639 100644 --- a/lib/ansible/modules/extras/database/misc/mongodb_user.py +++ b/lib/ansible/modules/extras/database/misc/mongodb_user.py @@ -278,7 +278,7 @@ def main(): uinfo = user_find(client, user, db_name) if update_password != 'always' and uinfo: password = None - if list(map((lambda x: x['role']), uinfo['roles'])) == roles: + if 'roles' in uinfo and list(map((lambda x: x['role']), uinfo['roles'])) == roles: module.exit_json(changed=False, user=user) if module.check_mode: