An Ansible role for creating and updating Red Hat Support Cases via the API.
This unified role provides comprehensive support case management capabilities, combining the functionality of creating new cases and updating existing ones. The role automatically detects the operation mode based on the provided variables:
- Create Mode: Creates a new Red Hat Support Case
- Update Mode: Updates an existing case with attachments and/or comments
- Hybrid Mode: Creates a new case and immediately updates it with attachments/comments
- Automated case creation – Creates support cases via the Red Hat Support API
- Case ID retrieval – Returns the newly created case ID for use in subsequent tasks
- File uploads – Uploads files of any size using
curlfor robust streaming support - Comment support – Adds comments in either
markdownorplaintextformat - Batch operations – Process multiple attachments and comments in a single run
- Template-based comments – Supports Jinja2 templates for customizable initial case comments
- Account validation – Retrieves and validates account information from the API token
- Unified interface – Single role for all case operations
- On Control Node (Execution Host):
- Network access to the Red Hat API endpoint (
https://api.access.redhat.com) - A valid Red Hat API access token (provided by the
rh_token_refreshrole) curl: Required for file uploads (must be installed and in the system'sPATH)
- Network access to the Red Hat API endpoint (
The role automatically determines the operation mode based on the variables provided:
Triggered when:
case_idis NOT defined (or empty)- Case creation fields are provided (
case_summary,case_product, etc.)
Required Variables:
case_summarycase_productcase_descriptioncase_product_versioncase_typecase_severity
Triggered when:
case_idIS definedcase_updates_neededis provided
Required Variables:
case_idcase_updates_needed(list)
Triggered when:
case_idis NOT defined (or empty)- Case creation fields are provided
case_updates_neededis provided
Required Variables:
- All create mode variables
case_updates_needed(list)
| Variable | Description | Type | Required | Default |
|---|---|---|---|---|
rh_token_refresh_api_access_token |
A valid, current Red Hat API access token. Typically provided as a fact by the rh_token_refresh role. |
string |
Yes | Supplied as fact |
| Variable | Description | Type | Required | Default |
|---|---|---|---|---|
case_summary |
The mandatory title/summary for the new support case. | string |
Yes* | — |
case_description |
The detailed description of the issue. | string |
Yes* | — |
case_product |
The exact, valid name of the Red Hat product (e.g., "OpenShift Container Platform"). |
string |
Yes* | — |
case_product_version |
The normalized base version string for the product (e.g., "4.16" for OpenShift, "8.9" for RHEL). |
string |
Yes* | — |
case_type |
The mandatory type of issue (e.g., "Configuration Issue"). |
string |
Yes* | — |
case_severity |
The severity level (e.g., "3 (Normal)"). |
string |
Yes* | — |
cluster_id |
Optional cluster ID to associate with the case (for OpenShift). | string |
No | — |
* Required for create/hybrid mode only
| Variable | Description | Type | Required | Default |
|---|---|---|---|---|
case_id |
The Red Hat Support Case number (e.g., 01234567). |
string |
Yes* | — |
case_updates_needed |
A list of objects defining attachments to upload or comments to add. | list |
Yes* | — |
* Required for update/hybrid mode only
Each item in the case_updates_needed list can contain:
| Field | Description | Type | Required |
|---|---|---|---|
attachment |
Full path to the local file to upload. | string |
No* |
attachmentDescription |
Description for the file being attached. | string |
No |
comment |
Text of the comment to add to the case. | string |
No* |
commentType |
Format of the comment: markdown (default) or plaintext. |
string |
No |
* Each object must contain either
attachmentorcomment(or both).
| Variable | Description | Type |
|---|---|---|
new_case_id |
The ID of the newly created support case (e.g., 00000000). Set as a global fact for subsequent roles. |
string |
case_id |
Set to new_case_id after case creation, or uses provided case_id for updates. |
string |
account_name |
The name of the organization associated with the API token. | string |
accountNumberRef |
The numeric account ID required for API submission. | string |
| Variable | Description | Type | Required | Default |
|---|---|---|---|---|
rh_case_http_proxy |
HTTP/HTTPS proxy URL for API requests (e.g., http://proxy.example.com:8080). |
string |
No | "" |
rh_case_use_proxy |
Whether to use proxy for this role (falls back to use_proxy). |
bool |
No | false |
rh_case_no_log |
Suppress sensitive output in logs. | bool |
No | true |
rh_case_timeout |
Timeout in seconds for each curl file upload command. |
int |
No | 1800 (30 min) |
rh_case_post_create_comment |
Whether to post initial comment after case creation. | bool |
No | true |
initial_comment_type |
Content type for initial post-creation comment (markdown or plaintext). |
string |
No | markdown |
- This role must be run after
infra.support_assist.rh_token_refreshto populate the requiredrh_token_refresh_api_access_tokenfact.
For the fields case_product, case_type, and case_severity, the acceptable values must exactly match the Red Hat Support API's lookup tables.
Please consult the dedicated documentation file for the full list of valid options:
Full Case Option Lists: docs/CASE_OPTIONS.md
---
- name: Create New Red Hat Support Case
hosts: localhost
connection: local
gather_facts: false
vars:
# --- REQUIRED AUTHENTICATION INPUTS ---
offline_token: "YOUR_OFFLINE_TOKEN_HERE" # Use Ansible Vault!
# --- REQUIRED CASE INPUTS ---
case_summary: "Example Support Case Created via Ansible Automation"
case_description: |
This is an example support case created via the
infra.support_assist.rh_case role in Ansible.
case_product: "Red Hat Enterprise Linux"
case_product_version: "8.9"
case_type: "Defect / Bug"
case_severity: "2 (High)"
tasks:
- name: Ensure API Access Token is fresh
ansible.builtin.include_role:
name: infra.support_assist.rh_token_refresh
- name: Create the support case
ansible.builtin.include_role:
name: infra.support_assist.rh_case
- name: Display the new case ID
ansible.builtin.debug:
msg: "Created case: {{ new_case_id }}"---
- name: Update Red Hat Support Case
hosts: localhost
connection: local
gather_facts: false
vars:
offline_token: "{{ vault_offline_token }}"
case_id: "01234567"
case_updates_needed:
- attachment: "/var/log/my-custom-app.log"
attachmentDescription: "Custom log file from my-server-01"
- comment: "This is a test comment added via Ansible."
commentType: "plaintext"
tasks:
- name: Refresh API token
ansible.builtin.include_role:
name: infra.support_assist.rh_token_refresh
- name: Update the case
ansible.builtin.include_role:
name: infra.support_assist.rh_case---
- name: Create and Update Red Hat Support Case
hosts: localhost
connection: local
gather_facts: false
vars:
offline_token: "{{ vault_offline_token }}"
# Case creation fields
case_summary: "Pod scheduling issues after upgrade"
case_description: |
After upgrading from OCP 4.15 to 4.16, pods are failing to schedule
on worker nodes. The scheduler reports resource constraints but
nodes show available capacity.
case_product: "OpenShift Container Platform"
case_product_version: "4.16"
case_type: "Defect / Bug"
case_severity: "2 (High)"
# Updates to apply after creation
case_updates_needed:
- attachment: "/tmp/must-gather.tar.gz"
attachmentDescription: "OCP must-gather output"
- comment: |
### Automation Complete
Attached is the `must-gather` output from the cluster.
commentType: "markdown"
tasks:
- name: Refresh API token
ansible.builtin.include_role:
name: infra.support_assist.rh_token_refresh
- name: Create and update support case
ansible.builtin.include_role:
name: infra.support_assist.rh_case
- name: Display the new case ID
ansible.builtin.debug:
msg: "Created and updated case: {{ new_case_id }}"---
- name: Create OpenShift Support Case
hosts: localhost
connection: local
gather_facts: false
vars:
offline_token: "{{ vault_offline_token }}"
case_summary: "Cluster connectivity issues"
case_description: "Experiencing intermittent connectivity issues between nodes."
case_product: "OpenShift Container Platform"
case_product_version: "4.16"
case_type: "Configuration Issue"
case_severity: "3 (Normal)"
cluster_id: "abc123-def456-ghi789"
tasks:
- name: Refresh API token
ansible.builtin.include_role:
name: infra.support_assist.rh_token_refresh
- name: Create support case
ansible.builtin.include_role:
name: infra.support_assist.rh_case---
- name: Perform multiple case updates
hosts: localhost
connection: local
gather_facts: false
vars:
case_id: "01234567"
offline_token: "{{ vault_offline_token }}"
case_updates_needed:
- attachment: "/tmp/sos_reports/case_01234567/server1/sosreport-server1.tar.xz"
attachmentDescription: "SOS Report from server1"
- attachment: "/tmp/sos_reports/case_01234567/server2/sosreport-server2.tar.xz"
attachmentDescription: "SOS Report from server2"
- comment: |
### Automation Complete
Attached are the `sosreport` files from the following hosts:
* `server1.example.com`
* `server2.example.com`
commentType: "markdown"
tasks:
- name: Refresh API token
ansible.builtin.include_role:
name: infra.support_assist.rh_token_refresh
- name: Update case with files and comment
ansible.builtin.include_role:
name: infra.support_assist.rh_caseThe content of the automatic comment posted after case creation can be customized via the Jinja2 template:
templates/support_case_comment.j2
To disable the automatic post-creation comment, set rh_case_post_create_comment: false.
┌─────────────────────────────────────────────────────────────────┐
│ rh_case │
├─────────────────────────────────────────────────────────────────┤
│ 1. Mode Detection │
│ └── Determines: create, update, or hybrid │
│ │
│ 2. Pre-validation │
│ ├── Verify API token │
│ ├── Retrieve account info │
│ ├── Validate create fields (if create/hybrid) │
│ └── Validate update fields (if update/hybrid) │
│ │
│ 3. Create Case (if create/hybrid) │
│ ├── Build case payload │
│ ├── POST to /v1/cases │
│ ├── Validate response │
│ └── Extract case_id │
│ │
│ 4. Post-Creation Comment (if enabled) │
│ └── POST comment via template │
│ │
│ 5. Update Case (if update/hybrid) │
│ └── Loop through case_updates_needed │
│ ├── Upload attachments (via curl) │
│ └── Add comments │
│ │
│ 6. Display Summary │
│ └── Show case details and URL │
└─────────────────────────────────────────────────────────────────┘
GPL-3.0-or-later
- Authors: Lenny Shirley, Diego Felipe Mateus
- Company: Red Hat
- Collection: infra.support_assist
This role is typically used in conjunction with other roles in the infra.support_assist collection:
rh_token_refresh– Handle Red Hat API token authentication and caching (required dependency)ocp_must_gather– Gather OpenShift diagnosticssos_report– Generate SOS reportsaap_api_gather– Gather diagnostic output from AAP component APIs