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 <noreply@anthropic.com>

* Add changelog fragment for PR 11859

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Alexei Znamensky
2026-04-17 23:46:48 +12:00
committed by GitHub
parent 3416efa5bf
commit dad84dd36d
2 changed files with 19 additions and 5 deletions

View File

@@ -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).

View File

@@ -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: