Debian Codegraph @

ansible_collections/splunk/es/plugins/modules/splunk_response_plan.py

raw
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
11 short_description: Manage Splunk Enterprise Security response plans
12 description:
13 - This module allows for creation, update, and deletion of Splunk Enterprise Security
14 response plans (response templates).
15 - Response plan names are unique in Splunk ES, so C(name) is used as the identifier.
16 - When C(state=present), the module creates or updates the response plan.
17 - When C(state=absent), the module deletes the response plan.
18 - Phases and tasks are matched by name for updates - existing IDs are preserved
19 for items with matching names, and new IDs are generated for new items.
20 - B(IMPORTANT - Declarative Approach:) This module uses a declarative approach where the
21 playbook defines the complete desired state. Whatever you define is exactly what will
22 exist after the module runs. Any existing phases, tasks, or searches that are NOT
23 included in your playbook will be REMOVED. This is not a merge operation - it is a
24 full replacement of the response plan structure.
25 - For example, if a response plan has phases A, B, C and you only define phase A in your
26 playbook, phases B and C will be deleted. The same applies to tasks within phases and
27 searches within tasks.
28 version_added: "5.1.0"
29 options:
30 name:
31 description:
32 - The name of the response plan.
33 - This is the unique identifier and is always required.
34 - Used to look up existing response plans for update or delete operations.
35 type: str
36 required: true
37 description:
38 description:
39 - The description of the response plan.
40 type: str
41 template_status:
42 description:
43 - The status of the response plan template.
44 - Use C(draft) for work-in-progress plans.
45 - Use C(published) for plans ready for use.
46 type: str
47 choices:
48 - published
49 - draft
50 default: draft
51 phases:
52 description:
53 - List of phases in the response plan.
54 - Required when C(state=present).
55 - Phases are matched by name for updates.
56 - B(Note:) Only phases defined here will exist after update. Any existing phases
57 not included in this list will be removed from the response plan.
58 type: list
59 elements: dict
60 suboptions:
61 name:
62 description:
63 - The name of the phase.
64 - Used as identifier for matching during updates.
65 type: str
66 required: true
67 tasks:
68 description:
69 - List of tasks in the phase.
70 - Tasks are matched by name within their parent phase for updates.
71 - B(Note:) Only tasks defined here will exist in the phase after update.
72 Any existing tasks not included in this list will be removed.
73 type: list
74 elements: dict
75 suboptions:
76 name:
77 description:
78 - The name of the task.
79 - Used as identifier for matching during updates.
80 type: str
81 required: true
82 description:
83 description:
84 - The description of the task.
85 type: str
86 is_note_required:
87 description:
88 - Whether a note is required when completing the task.
89 type: bool
90 default: false
91 owner:
92 description:
93 - The owner of the task.
94 - Use C(admin) for the administrator user.
95 - Use C(unassigned) to leave the task unassigned.
96 type: str
97 default: unassigned
98 searches:
99 description:
100 - List of saved searches to attach to the task.
101 - Searches are replaced entirely on update (not merged).
102 type: list
103 elements: dict
104 suboptions:
105 name:
106 description:
107 - The name of the search.
108 type: str
109 required: true
110 description:
111 description:
112 - The description of the search.
113 type: str
114 spl:
115 description:
116 - The SPL (Search Processing Language) query.
117 type: str
118 required: true
119 state:
120 description:
121 - The desired state of the response plan.
122 - Use C(present) to create or update the response plan.
123 - Use C(absent) to delete the response plan.
124 type: str
125 choices:
126 - present
127 - absent
128 default: present
129 api_namespace:
130 description:
131 - The namespace portion of the Splunk API path.
132 - Override this if your environment uses a different namespace.
133 type: str
134 default: servicesNS
135 api_user:
136 description:
137 - The user portion of the Splunk API path.
138 - Override this if your environment requires a different user context.
139 type: str
140 default: nobody
141 api_app:
142 description:
143 - The app portion of the Splunk API path for the response templates endpoint.
144 - Override this if your environment uses a different app name.
145 type: str
146 default: missioncontrol
147
148 author: Ron Gershburg (@rgershbu)
149 """
150
151 EXAMPLES = """
152 # Create a new response plan with phases and tasks
153 - name: Create incident response plan
154 splunk.es.splunk_response_plan:
155 name: "Incident Response Plan"
156 description: "Standard incident response procedure"
157 template_status: published
158 phases:
159 - name: "Investigation"
160 tasks:
161 - name: "Initial Triage"
162 description: "Perform initial assessment of the incident"
163 is_note_required: true
164 owner: admin
165 searches:
166 - name: "Access Over Time"
167 description: "Check access patterns"
168 spl: "| tstats count from datamodel=Authentication by _time span=10m"
169 - name: "Gather Evidence"
170 description: "Collect relevant logs and artifacts"
171 is_note_required: false
172 - name: "Containment"
173 tasks:
174 - name: "Isolate Affected Systems"
175 description: "Isolate compromised hosts from network"
176 is_note_required: true
177
178 # Create a draft response plan
179 - name: Create draft response plan
180 splunk.es.splunk_response_plan:
181 name: "New Response Workflow"
182 description: "Work in progress response plan"
183 template_status: draft
184 phases:
185 - name: "Phase 1"
186 tasks:
187 - name: "Task 1"
188 description: "First task"
189
190 # Update an existing response plan (adds new task, updates existing)
191 - name: Update response plan
192 splunk.es.splunk_response_plan:
193 name: "Incident Response Plan"
194 description: "Updated incident response procedure"
195 template_status: published
196 phases:
197 - name: "Investigation"
198 tasks:
199 - name: "Initial Triage"
200 description: "Updated: Perform thorough initial assessment"
201 is_note_required: true
202 - name: "New Analysis Task"
203 description: "This task will be created"
204 is_note_required: false
205 - name: "Containment"
206 tasks:
207 - name: "Isolate Affected Systems"
208 description: "Isolate compromised hosts from network"
209
210 # Delete a response plan by name
211 - name: Delete response plan
212 splunk.es.splunk_response_plan:
213 name: "Incident Response Plan"
214 state: absent
215
216 # Example: Declarative update - removes phases/tasks not defined
217 # If the response plan currently has phases "Investigation", "Containment", "Recovery"
218 # but this playbook only defines "Investigation" and "Containment", then the
219 # "Recovery" phase will be DELETED. Same applies to tasks within phases.
220 - name: Update response plan (removes Recovery phase if it existed)
221 splunk.es.splunk_response_plan:
222 name: "Incident Response Plan"
223 description: "Updated procedure - Recovery phase removed"
224 template_status: published
225 phases:
226 - name: "Investigation"
227 tasks:
228 - name: "Initial Triage"
229 description: "Perform initial assessment"
230 - name: "Containment"
231 tasks:
232 - name: "Isolate Systems"
233 description: "Isolate affected systems"
234
235 # Create response plan with custom API path (for non-standard environments)
236 - name: Create response plan with custom API path
237 splunk.es.splunk_response_plan:
238 name: "Custom Response Plan"
239 description: "Response plan with custom API configuration"
240 template_status: published
241 api_namespace: "{{ es_namespace | default('servicesNS') }}"
242 api_user: "{{ es_user | default('nobody') }}"
243 api_app: "{{ es_app | default('missioncontrol') }}"
244 phases:
245 - name: "Phase 1"
246 tasks:
247 - name: "Task 1"
248 description: "First task"
249 """
250
251 RETURN = """
252 response_plan:
253 description: The response plan result containing before/after states.
254 returned: always
255 type: dict
256 contains:
257 before:
258 description: The response plan state before module execution (null if creating).
259 type: dict
260 returned: when response plan existed
261 after:
262 description: The response plan state after module execution (null if deleted).
263 type: dict
264 returned: always
265 sample:
266 before: null
267 after:
268 name: "Incident Response Plan"
269 description: "Standard incident response procedure"
270 template_status: "published"
271 phases:
272 - name: "Investigation"
273 tasks:
274 - name: "Initial Triage"
275 description: "Perform initial assessment"
276 is_note_required: true
277 owner: "admin"
278 searches:
279 - name: "Access Over Time"
280 description: "Check access patterns"
281 spl: "| tstats count from datamodel=Authentication"
282 changed:
283 description: Whether any changes were made.
284 returned: always
285 type: bool
286 sample: true
287 msg:
288 description: Message describing the result.
289 returned: always
290 type: str
291 sample: "Response plan created successfully"
292 """