From dad84dd36d10f94afba7a7d6ee3330dc4e447a4d Mon Sep 17 00:00:00 2001 From: Alexei Znamensky <103110+russoz@users.noreply.github.com> Date: Fri, 17 Apr 2026 23:46:48 +1200 Subject: [PATCH] udm_user - fix alias-to-canonical param name mismatch (#11859) * udm_user - fix alias-to-canonical param name mismatch The loop that maps UDM object properties to module params iterated over UDM keys (camelCase, e.g. displayName, primaryGroup) and looked them up directly in module.params, which is keyed by canonical names (snake_case, e.g. display_name, primary_group). This caused all aliased params to be silently ignored. Build an alias-to-canonical mapping from argument_spec and use it to resolve UDM keys to the correct module.params entries. Also fix the direct module.params["displayName"] access which raised KeyError when the user did not explicitly use the alias form. Fixes #2950 Fixes #3691 Co-Authored-By: Claude Opus 4.6 * Add changelog fragment for PR 11859 Co-Authored-By: Claude Opus 4.6 --------- Co-authored-by: Claude Opus 4.6 --- .../11859-udm_user-param-name-fix.yml | 6 ++++++ plugins/modules/udm_user.py | 18 +++++++++++++----- 2 files changed, 19 insertions(+), 5 deletions(-) create mode 100644 changelogs/fragments/11859-udm_user-param-name-fix.yml diff --git a/changelogs/fragments/11859-udm_user-param-name-fix.yml b/changelogs/fragments/11859-udm_user-param-name-fix.yml new file mode 100644 index 0000000000..50056906c9 --- /dev/null +++ b/changelogs/fragments/11859-udm_user-param-name-fix.yml @@ -0,0 +1,6 @@ +bugfixes: + - udm_user - fix alias-to-canonical parameter name mismatch that caused all camelCase-aliased + parameters such as ``display_name`` and ``primary_group`` to be silently ignored + (https://github.com/ansible-collections/community.general/issues/2950, + https://github.com/ansible-collections/community.general/issues/3691, + https://github.com/ansible-collections/community.general/pull/11859). diff --git a/plugins/modules/udm_user.py b/plugins/modules/udm_user.py index e807261244..e915637b57 100644 --- a/plugins/modules/udm_user.py +++ b/plugins/modules/udm_user.py @@ -444,19 +444,27 @@ def main(): else: obj = umc_module_for_edit("users/user", user_dn) - if module.params["displayName"] is None: - module.params["displayName"] = f"{module.params['firstname']} {module.params['lastname']}" + if module.params["display_name"] is None: + module.params["display_name"] = f"{module.params['firstname']} {module.params['lastname']}" if module.params["unixhome"] is None: module.params["unixhome"] = f"/home/{module.params['username']}" + # Build a mapping from alias names to canonical param names, + # so that UDM object keys (camelCase) can be resolved to the + # corresponding module.params keys (snake_case). + alias_to_param = {} + for param_name, param_spec in module.argument_spec.items(): + for alias in param_spec.get("aliases", []): + alias_to_param[alias] = param_name for k in obj.keys(): + param_name = alias_to_param.get(k, k) if ( k != "password" and k != "groups" and k != "overridePWHistory" - and k in module.params - and module.params[k] is not None + and param_name in module.params + and module.params[param_name] is not None ): - obj[k] = module.params[k] + obj[k] = module.params[param_name] # handle some special values obj["e-mail"] = module.params["email"] if "userexpiry" in obj and obj.get("userexpiry") is None: