[AAP-75240] Fix role_team_assignment content_type mismatch causing 4… - #192
Open
rohitthakur2590 wants to merge 5 commits into
Open
[AAP-75240] Fix role_team_assignment content_type mismatch causing 4…#192rohitthakur2590 wants to merge 5 commits into
rohitthakur2590 wants to merge 5 commits into
Conversation
…0/500 errors and enable resource-level type support Signed-off-by: rohitthakur2590 <rohitthakur2590@outlook.com>
Signed-off-by: rohitthakur2590 <rohitthakur2590@outlook.com>
Signed-off-by: rohitthakur2590 <rohitthakur2590@outlook.com>
Signed-off-by: rohitthakur2590 <rohitthakur2590@outlook.com>
|
DVCS PR Check Results: PR appears valid (JIRA key(s) found) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
…00/500 errors and enable resource-level type support
Description
Three changes in plugins/modules/role_team_assignment.py:
Replaced the hardcoded allowed type list in _validate_selector() , the old code only permitted type: organizations and type: teams in assignment_objects. It now accepts all resource-level types (projects, inventories, credentials, job_templates, activations, event_streams, decision_environments, and all Hub/Galaxy types) by deriving the allowed set dynamically from a new CONTENT_TYPE_ENDPOINT_MAP constant.
Added type-match validation , when a user provides type: in assignment_objects, the module now validates that it matches what the role definition's content_type actually expects. A mismatch produces a clear, actionable error message instead of a cryptic 400/500 from the Gateway API.
Changed the gate in main() from elif entity_type and object_param: to elif object_param: the block now runs whenever assignment_objects is provided, regardless of whether the role has a content_type. This also correctly handles the object_id and object_ansible_id paths within the loop.
The bug was introduced in v2.6.20260306 when the entity_type derivation changed from prefix-matching on the role name to reading content_type directly from the API response. This was architecturally correct but exposed two pre-existing problems:
Bug 1 (400/500): A role like "Launch User Role - Projects" has content_type = "awx.project". When combined with type: organizations in assignment_objects, the module correctly looked up the organization (id=42) but then sent that org ID as object_id for a role the Gateway API expects to point at a project. The API rejected it with 400 "Project matching query does not exist." or 500 Internal Server Error. Before v2.6.20260306 this was a silent no-op (nothing was assigned) because the old prefix-matching code set entity_type = None for non-"Team"/"Organization" role names, skipping the block entirely.
Bug 2 (blocked type): Even users who correctly knew they needed type: projects for a project-scoped role could not use it — the hardcoded allowed = ("organizations", "teams") rejected it immediately with "Unsupported type 'projects'". This made it impossible to assign any resource-level role by name without falling back to ansible.builtin.uri directly.
The fix validates the type combination before any API call is made
Type of Change
Self-Review Checklist
Testing Instructions
Prerequisites
Steps to Test
Expected Results
Additional Context
Required Actions
Screenshots/Logs