Debian Codegraph @

ansible_collections/pcg/alpaca_operator/docs/alpaca_command_set.md

raw
1 # ALPACA Command Set Module
2
3 ## Overview
4
5 The `pcg.alpaca_operator.alpaca_command_set` module manages an entire set of [ALPACA Operator](https://alpaca.pcg.io/) commands associated with a system using a REST API. It is designed to apply bulk changes, for example, deploying multiple commands at once or cleaning up an existing command set.
6
7 Use this module when you need to apply or remove multiple commands at once on a given ALPACA system. It simplifies large-scale system updates and is optimal for automation scenarios.
8
9 **Important**: This module takes full control of the command set on the target system. Any commands not defined via Ansible will be removed from the system!
10
11 ## Module Information
12
13 - **Module Name**: `pcg.alpaca_operator.alpaca_command_set`
14 - **Short Description**: Manage all ALPACA Operator commands of a specific system via REST API
15 - **Version Added**: 1.0.0
16 - **Requirements**:
17 - Python >= 3.9
18 - ansible-core >= 2.12
19 - ALPACA Operator >= 5.6.0
20
21 ## Parameters
22
23 ### Required Parameters
24
25 | Parameter | Type | Required | Description |
26 | --------------- | ---- | -------- | ------------------------------------------------------------------------------------------------ |
27 | `system` | dict | Yes | Dictionary containing system identification. Either `system_id` or `system_name` must be provided. |
28 | `api_connection` | dict | Yes | Connection details for accessing the ALPACA Operator API |
29
30 ### Optional Parameters
31
32 | Parameter | Type | Required | Default | Description |
33 | ---------- | ---- | -------- | ------- | ---------------------------------- |
34 | `commands` | list | No | [] | List of desired commands to manage |
35
36 ### System Identification
37
38 The `system` parameter accepts a dictionary with the following sub-options:
39
40 | Parameter | Type | Required | Description |
41 | ------------ | ---- | -------- | ---------------------------------------------------------------------- |
42 | `system_id` | int | No* | Numeric ID of the target system. Optional if `system_name` is provided. |
43 | `system_name` | str | No* | Name of the target system. Optional if `system_id` is provided. |
44
45 *Either `system_id` or `system_name` must be provided.
46
47 ### Command Configuration
48
49 The `commands` parameter accepts a list of dictionaries, where each dictionary can include the following fields:
50
51 | Parameter | Type | Required | Default | Description |
52 | ------------------ | ---- | -------- | ------- | ------------------------------------------------------------------------------------------ |
53 | `name` | str | No | - | Name or description of the command |
54 | `state` | str | No | present | Desired state of the command (present, absent) |
55 | `agent_id` | int | No | - | Numeric ID of the agent. Optional if `agent_name` is provided. |
56 | `agent_name` | str | No | - | Name of the agent. Optional if `agent_id` is provided. |
57 | `process_id` | int | No | - | ID of the process to be executed. Optional if `process_central_id` is provided. |
58 | `process_central_id` | int | No | - | Central ID / Global ID of the process to be executed. Optional if `process_id` is provided. |
59 | `parameters` | str | No | - | Parameters for the process |
60 | `parameters_needed` | bool | No | - | Whether the execution of the command requires additional parameters |
61 | `disabled` | bool | No | - | Whether the command is currently disabled |
62 | `critical` | bool | No | - | Whether the command is marked as critical |
63 | `auto_deploy` | bool | No | - | Whether to automatically deploy the command |
64
65 ### Schedule Configuration
66
67 The `schedule` parameter accepts a dictionary with the following sub-options:
68
69 | Parameter | Type | Required | Description |
70 | ---------------- | ---- | -------- | ----------------------------------------------------------------------------------------------------------------------- |
71 | `period` | str | No | Scheduling period |
72 | `time` | str | No | Execution time in HH:mm:ss. Required when period is 'fixed_time', 'fixed_time_once' or 'start_fixed_time_and_hourly_mn' |
73 | `cron_expression` | str | No | Quartz-compatible cron expression. Required when period is 'cron_expression' |
74 | `days_of_week` | list | No | List of weekdays for execution |
75
76 **Period Choices**: every_5min, one_per_day, hourly, manually, fixed_time, hourly_with_mn, every_minute, even_hours_with_mn, odd_hours_with_mn, even_hours, odd_hours, fixed_time_once, fixed_time_immediate, cron_expression, disabled, start_fixed_time_and_hourly_mn
77
78 **Days of Week Choices**: monday, tuesday, wednesday, thursday, friday, saturday, sunday
79
80 ### History Configuration
81
82 The `history` parameter accepts a dictionary with the following sub-options:
83
84 | Parameter | Type | Required | Description |
85 | ------------------- | ---- | -------- | ---------------------------------- |
86 | `document_all_runs` | bool | No | Whether to document all executions |
87 | `retention` | int | No | Retention time in seconds |
88
89 ### Timeout Configuration
90
91 The `timeout` parameter accepts a dictionary with the following sub-options:
92
93 | Parameter | Type | Required | Description |
94 | --------- | ---- | -------- | ------------------------------------------ |
95 | `type` | str | No | Type of timeout (none, default, or custom) |
96 | `value` | int | No | Timeout value in seconds (for custom type) |
97
98 **Type Choices**: none, default, custom
99
100 ### Escalation Configuration
101
102 The `escalation` parameter accepts a dictionary with the following sub-options:
103
104 | Parameter | Type | Required | Description |
105 | ------------------- | ---- | -------- | -------------------------------------------- |
106 | `mail_enabled` | bool | No | Whether email alerts are enabled |
107 | `sms_enabled` | bool | No | Whether SMS alerts are enabled |
108 | `mail_address` | str | No | Email address for alerts |
109 | `sms_address` | str | No | SMS number for alerts |
110 | `min_failure_count` | int | No | Minimum number of failures before escalation |
111 | `triggers` | dict | No | Trigger types for escalation |
112
113 ### Escalation Triggers
114
115 The `triggers` parameter accepts a dictionary with the following sub-options:
116
117 | Parameter | Type | Required | Description |
118 | -------------- | ---- | -------- | ---------------------------------- |
119 | `every_change` | bool | No | Currently no description available |
120 | `to_red` | bool | No | Currently no description available |
121 | `to_yellow` | bool | No | Currently no description available |
122 | `to_green` | bool | No | Currently no description available |
123
124 ### API Connection Configuration
125
126 The `api_connection` parameter requires a dictionary with the following sub-options:
127
128 | Parameter | Type | Required | Default | Description |
129 | ------------ | ---- | -------- | --------- | ----------------------------------------------------------- |
130 | `username` | str | Yes | - | Username for authentication against the ALPACA Operator API |
131 | `password` | str | Yes | - | Password for authentication against the ALPACA Operator API |
132 | `protocol` | str | No | https | Protocol to use (http or https) |
133 | `host` | str | No | localhost | Hostname of the ALPACA Operator server |
134 | `port` | int | No | 8443 | Port of the ALPACA Operator API |
135 | `tls_verify` | bool | No | true | Validate SSL certificates |
136
137 ## Examples
138
139 ### Configure Multiple Commands
140
141 ```yaml
142 - name: Ensure that multiple commands are configured correctly on system01
143 hosts: local
144 gather_facts: false
145
146 vars:
147 api_connection:
148 host: "{{ ALPACA_Operator_API_Host }}"
149 protocol: "{{ ALPACA_Operator_API_Protocol }}"
150 port: "{{ ALPACA_Operator_API_Port }}"
151 username: "{{ ALPACA_Operator_API_Username }}"
152 password: "{{ ALPACA_Operator_API_Password }}"
153 tls_verify: "{{ ALPACA_Operator_API_Validate_Certs }}"
154
155 tasks:
156 - name: Configure commands
157 pcg.alpaca_operator.alpaca_command_set:
158 system:
159 system_name: system01
160 commands:
161 - name: "BKP: DB log sync"
162 state: present
163 agent_name: agent01
164 parameters: "-p GLTarch -s <BKP_LOG_SRC> -l 4 -d <BKP_LOG_DEST1> -r <BKP_LOG_DEST2> -b <BKP_LOG_CLEANUP_INT> -t <BKP_LOG_CLEANUP_INT2> -h DB_HOST"
165 process_central_id: 8990048
166 schedule:
167 period: manually
168 time: "01:00:00"
169 days_of_week:
170 - monday
171 - sunday
172 parameters_needed: false
173 disabled: false
174 critical: true
175 history:
176 document_all_runs: true
177 retention: 900
178 auto_deploy: false
179 timeout:
180 type: default
181 value: 30
182 escalation:
183 mail_enabled: true
184 sms_enabled: true
185 mail_address: "[email protected]"
186 sms_address: "0123456789"
187 min_failure_count: 1
188 triggers:
189 every_change: true
190 to_red: false
191 to_yellow: false
192 to_green: true
193 - name: "BKP: DB log sync 2"
194 state: present
195 agent_name: agent02
196 parameters: "-p GLTarch -s <BKP_LOG_SRC> -l 4 -d <BKP_LOG_DEST1> -r <BKP_LOG_DEST2> -b <BKP_LOG_CLEANUP_INT> -t <BKP_LOG_CLEANUP_INT2> -h DB_HOST"
197 process_central_id: 8990048
198 schedule:
199 period: cron_expression
200 cron_expression: '0 */5 * * * ?'
201 parameters_needed: false
202 disabled: false
203 critical: true
204 history:
205 document_all_runs: true
206 retention: 900
207 auto_deploy: false
208 timeout:
209 type: default
210 value: 30
211 escalation:
212 mail_enabled: true
213 sms_enabled: true
214 mail_address: "[email protected]"
215 sms_address: "0123456789"
216 min_failure_count: 1
217 triggers:
218 every_change: true
219 to_red: false
220 to_yellow: false
221 to_green: true
222 api_connection: "{{ api_connection }}"
223 ```
224
225 ### Remove All Commands
226
227 ```yaml
228 - name: Remove all commands from system system01
229 hosts: local
230 gather_facts: false
231
232 vars:
233 api_connection:
234 host: "{{ ALPACA_Operator_API_Host }}"
235 protocol: "{{ ALPACA_Operator_API_Protocol }}"
236 port: "{{ ALPACA_Operator_API_Port }}"
237 username: "{{ ALPACA_Operator_API_Username }}"
238 password: "{{ ALPACA_Operator_API_Password }}"
239 tls_verify: "{{ ALPACA_Operator_API_Validate_Certs }}"
240
241 tasks:
242 - name: Remove all commands
243 pcg.alpaca_operator.alpaca_command_set:
244 system:
245 system_name: system01
246 commands: []
247 api_connection: "{{ api_connection }}"
248 ```
249
250 ## Return Values
251
252 | Parameter | Type | Returned | Description |
253 | --------- | ---- | ------------------------- | ----------------------------------------------------------------- |
254 | `msg` | str | always | Status message |
255 | `changed` | bool | always | Whether any change was made |
256 | `changes` | dict | when changes are detected | A dictionary describing all changes that were or would be applied |
257
258 ### Changes Dictionary Structure
259
260 The `changes` dictionary typically follows the format `commandIndex_XXX`, representing the index in the `commands` list. Each entry includes diffs between the current and desired state. Also includes `removed_commands` if commands were deleted.
261
262 #### Example Changes Structure
263
264 ```json
265 {
266 "commandIndex_000": {
267 "parameters": {
268 "current": "-p foo -s A -d B",
269 "desired": "-p foo -s A -d B -t X"
270 },
271 "schedule": {
272 "period": {
273 "current": "manually",
274 "desired": "every_minute"
275 }
276 }
277 },
278 "commandIndex_001": {
279 "escalation": {
280 "min_failure_count": {
281 "current": 0,
282 "desired": 1
283 }
284 }
285 },
286 "removed_commands": [
287 "Old Command Name 1",
288 "Old Command Name 2"
289 ]
290 }
291 ```
292
293 ## Notes
294
295 - **Critical Warning**: This module takes full control of the command set. Any commands not defined in the `commands` list will be removed from the system.
296 - The module supports check mode for previewing changes without applying them
297 - Commands are uniquely identified by name and agent assignment
298 - When updating existing commands, only specified fields are modified
299 - The agent must be assigned to the corresponding system if managed via Ansible
300 - Schedule configurations support various periodic execution patterns including cron expressions
301 - Escalation settings can be configured for both email and SMS notifications
302 - Use this module for bulk operations rather than individual command management
303 - Empty commands list will remove all commands from the system
304 - API connection variables should be stored in the inventory file and referenced via `api_connection: "{{ api_connection }}"` in playbooks
305
306 ## Author
307
308 - Jan-Karsten Hansmeyer (@pcg)