| 1 |
#!/usr/bin/python |
| 2 |
# -*- coding: utf-8 -*- |
| 3 |
|
| 4 |
# Copyright 2026 Red Hat Inc. |
| 5 |
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) |
| 6 |
|
| 7 |
|
| 8 |
DOCUMENTATION = """ |
| 9 |
--- |
| 10 |
module: splunk_response_plan_execution |
| 11 |
short_description: Apply response plans to investigations and manage tasks |
| 12 |
description: |
| 13 |
- This module applies or removes response plans from Splunk Enterprise Security investigations. |
| 14 |
- It also manages task lifecycle within applied response plans (start, end, change owner). |
| 15 |
- The C(response_plan) parameter accepts either a UUID or a name. |
| 16 |
- When C(state=present), the response plan is applied to the investigation. |
| 17 |
- When C(state=absent), the response plan is removed from the investigation. |
| 18 |
- Use the C(tasks) parameter to manage individual task statuses and owners within the applied plan. |
| 19 |
version_added: "5.1.0" |
| 20 |
options: |
| 21 |
investigation_ref_id: |
| 22 |
description: |
| 23 |
- The investigation UUID to apply or manage response plans. |
| 24 |
- This is the unique identifier of the investigation in Splunk ES. |
| 25 |
type: str |
| 26 |
required: true |
| 27 |
response_plan: |
| 28 |
description: |
| 29 |
- The response plan template to apply or remove. |
| 30 |
- Accepts either a UUID (e.g., "2dc5530d-8bb0-4a4f-9b53-74745bf4ea6a") or a name |
| 31 |
(e.g., "Incident Response Plan"). |
| 32 |
- If UUID format is detected, it is used directly as the template ID. |
| 33 |
- If not a UUID, the module performs an API lookup to resolve the name to an ID. |
| 34 |
type: str |
| 35 |
required: true |
| 36 |
state: |
| 37 |
description: |
| 38 |
- The desired state of the response plan on the investigation. |
| 39 |
- Use C(present) to apply the response plan to the investigation or update the tasks. |
| 40 |
- Use C(absent) to remove the response plan from the investigation. |
| 41 |
type: str |
| 42 |
choices: |
| 43 |
- present |
| 44 |
- absent |
| 45 |
default: present |
| 46 |
tasks: |
| 47 |
description: |
| 48 |
- List of tasks to manage within the applied response plan. |
| 49 |
- Each task is identified by phase name and task name. |
| 50 |
- You can set the task status (started/ended) and/or change the owner. |
| 51 |
- Tasks are only managed when C(state=present). |
| 52 |
type: list |
| 53 |
elements: dict |
| 54 |
suboptions: |
| 55 |
phase_name: |
| 56 |
description: |
| 57 |
- The name of the phase containing the task. |
| 58 |
- Used to look up the phase ID within the applied response plan. |
| 59 |
type: str |
| 60 |
required: true |
| 61 |
task_name: |
| 62 |
description: |
| 63 |
- The name of the task to manage. |
| 64 |
- Used to look up the task ID within the phase. |
| 65 |
type: str |
| 66 |
required: true |
| 67 |
status: |
| 68 |
description: |
| 69 |
- The desired status of the task. |
| 70 |
- Use C(started) to mark the task as in progress. |
| 71 |
- Use C(ended) to mark the task as completed. |
| 72 |
- Use C(reopened) to reopen a completed task. |
| 73 |
type: str |
| 74 |
choices: |
| 75 |
- started |
| 76 |
- ended |
| 77 |
- reopened |
| 78 |
owner: |
| 79 |
description: |
| 80 |
- The owner/assignee of the task. |
| 81 |
- Use C(admin) for the administrator user. |
| 82 |
- Use C(unassigned) to remove the current owner or leave unassigned. |
| 83 |
type: str |
| 84 |
api_namespace: |
| 85 |
description: |
| 86 |
- The namespace portion of the Splunk API path. |
| 87 |
- Override this if your environment uses a different namespace. |
| 88 |
type: str |
| 89 |
default: servicesNS |
| 90 |
api_user: |
| 91 |
description: |
| 92 |
- The user portion of the Splunk API path. |
| 93 |
- Override this if your environment requires a different user context. |
| 94 |
type: str |
| 95 |
default: nobody |
| 96 |
api_app: |
| 97 |
description: |
| 98 |
- The app portion of the Splunk API path. |
| 99 |
- Override this if your environment uses a different app name. |
| 100 |
type: str |
| 101 |
default: missioncontrol |
| 102 |
|
| 103 |
author: Ron Gershburg (@rgershbu) |
| 104 |
""" |
| 105 |
|
| 106 |
EXAMPLES = """ |
| 107 |
# Apply a response plan to an investigation by name |
| 108 |
- name: Apply response plan to investigation |
| 109 |
splunk.es.splunk_response_plan_execution: |
| 110 |
investigation_ref_id: "590afa9c-23d5-4377-b909-cd2cfa1bc0f1" |
| 111 |
response_plan: "Incident Response Plan" |
| 112 |
state: present |
| 113 |
|
| 114 |
# Apply a response plan by UUID (no lookup needed) |
| 115 |
- name: Apply response plan by ID |
| 116 |
splunk.es.splunk_response_plan_execution: |
| 117 |
investigation_ref_id: "590afa9c-23d5-4377-b909-cd2cfa1bc0f1" |
| 118 |
response_plan: "2dc5530d-8bb0-4a4f-9b53-74745bf4ea6a" |
| 119 |
state: present |
| 120 |
|
| 121 |
# Apply response plan and start a task |
| 122 |
- name: Apply response plan and start initial triage |
| 123 |
splunk.es.splunk_response_plan_execution: |
| 124 |
investigation_ref_id: "590afa9c-23d5-4377-b909-cd2cfa1bc0f1" |
| 125 |
response_plan: "Incident Response Plan" |
| 126 |
state: present |
| 127 |
tasks: |
| 128 |
- phase_name: "Investigation Phase" |
| 129 |
task_name: "Initial Triage" |
| 130 |
status: started |
| 131 |
owner: admin |
| 132 |
|
| 133 |
# Manage multiple tasks in an applied response plan |
| 134 |
- name: Update multiple task statuses |
| 135 |
splunk.es.splunk_response_plan_execution: |
| 136 |
investigation_ref_id: "590afa9c-23d5-4377-b909-cd2cfa1bc0f1" |
| 137 |
response_plan: "Incident Response Plan" |
| 138 |
state: present |
| 139 |
tasks: |
| 140 |
- phase_name: "Investigation Phase" |
| 141 |
task_name: "Initial Triage" |
| 142 |
status: ended |
| 143 |
owner: admin |
| 144 |
- phase_name: "Investigation Phase" |
| 145 |
task_name: "Gather Evidence" |
| 146 |
status: started |
| 147 |
owner: analyst1 |
| 148 |
- phase_name: "Containment Phase" |
| 149 |
task_name: "Isolate Systems" |
| 150 |
owner: unassigned |
| 151 |
|
| 152 |
# Remove a response plan from an investigation |
| 153 |
- name: Remove response plan from investigation |
| 154 |
splunk.es.splunk_response_plan_execution: |
| 155 |
investigation_ref_id: "590afa9c-23d5-4377-b909-cd2cfa1bc0f1" |
| 156 |
response_plan: "Incident Response Plan" |
| 157 |
state: absent |
| 158 |
|
| 159 |
# Apply response plan with custom API configuration |
| 160 |
- name: Apply response plan with custom API path |
| 161 |
splunk.es.splunk_response_plan_execution: |
| 162 |
investigation_ref_id: "590afa9c-23d5-4377-b909-cd2cfa1bc0f1" |
| 163 |
response_plan: "Custom Response Plan" |
| 164 |
state: present |
| 165 |
api_namespace: "{{ es_namespace | default('servicesNS') }}" |
| 166 |
api_user: "{{ es_user | default('nobody') }}" |
| 167 |
api_app: "{{ es_app | default('missioncontrol') }}" |
| 168 |
""" |
| 169 |
|
| 170 |
RETURN = """ |
| 171 |
response_plan_execution: |
| 172 |
description: The response plan execution result containing before/after states. |
| 173 |
returned: always |
| 174 |
type: dict |
| 175 |
contains: |
| 176 |
before: |
| 177 |
description: The state before module execution. |
| 178 |
type: dict |
| 179 |
returned: always |
| 180 |
contains: |
| 181 |
applied: |
| 182 |
description: Whether the response plan was applied before execution. |
| 183 |
type: bool |
| 184 |
applied_plan_id: |
| 185 |
description: The ID of the applied response plan instance (if applied). |
| 186 |
type: str |
| 187 |
response_plan_id: |
| 188 |
description: The response plan template ID. |
| 189 |
type: str |
| 190 |
after: |
| 191 |
description: The state after module execution. |
| 192 |
type: dict |
| 193 |
returned: always |
| 194 |
contains: |
| 195 |
applied: |
| 196 |
description: Whether the response plan is applied after execution. |
| 197 |
type: bool |
| 198 |
applied_plan_id: |
| 199 |
description: The ID of the applied response plan instance (if applied). |
| 200 |
type: str |
| 201 |
response_plan_id: |
| 202 |
description: The response plan template ID. |
| 203 |
type: str |
| 204 |
tasks_updated: |
| 205 |
description: List of tasks that were updated (when tasks parameter is used). |
| 206 |
type: list |
| 207 |
elements: dict |
| 208 |
returned: when tasks parameter is provided |
| 209 |
contains: |
| 210 |
phase_name: |
| 211 |
description: The phase name containing the task. |
| 212 |
type: str |
| 213 |
task_name: |
| 214 |
description: The task name. |
| 215 |
type: str |
| 216 |
status: |
| 217 |
description: The task status after update. |
| 218 |
type: str |
| 219 |
owner: |
| 220 |
description: The task owner after update. |
| 221 |
type: str |
| 222 |
changed: |
| 223 |
description: Whether this specific task was changed. |
| 224 |
type: bool |
| 225 |
sample: |
| 226 |
before: |
| 227 |
applied: false |
| 228 |
after: |
| 229 |
applied: true |
| 230 |
applied_plan_id: "b9ef7dce-6dcd-4900-b5d5-982fc194554a" |
| 231 |
response_plan_id: "2dc5530d-8bb0-4a4f-9b53-74745bf4ea6a" |
| 232 |
tasks_updated: |
| 233 |
- phase_name: "Investigation Phase" |
| 234 |
task_name: "Initial Triage" |
| 235 |
status: "started" |
| 236 |
owner: "admin" |
| 237 |
changed: true |
| 238 |
changed: |
| 239 |
description: Whether any changes were made. |
| 240 |
returned: always |
| 241 |
type: bool |
| 242 |
sample: true |
| 243 |
msg: |
| 244 |
description: Message describing the result. |
| 245 |
returned: always |
| 246 |
type: str |
| 247 |
sample: "Response plan applied successfully" |
| 248 |
""" |