Debian Codegraph @

ansible_collections/pcg/alpaca_operator/docs/alpaca_command.md

raw
1 # ALPACA Command Module
2
3 ## Overview
4
5 The `pcg.alpaca_operator.alpaca_command` module manages a single [ALPACA Operator](https://alpaca.pcg.io/) command. It provides fine-grained control over individual command properties. Use this module when you need to configure or modify one specific command, such as changing its timeout, toggling disabled, or setting a new schedule.
6
7 Each command is uniquely identified by the combination of its name (description) and the assigned agentHostname. Note that renaming a command or reassigning it to a different agent is not supported by this module, as these properties are used for identification.
8
9 ## Module Information
10
11 - **Module Name**: `pcg.alpaca_operator.alpaca_command`
12 - **Short Description**: Manage a single ALPACA Operator command via REST API
13 - **Version Added**: 1.0.0
14 - **Requirements**:
15 - Python >= 3.9
16 - ansible-core >= 2.12
17 - ALPACA Operator >= 5.6.0
18
19 ## Update Behavior
20
21 If the desired command already exists, only the fields required for unique identification need to be provided (i.e., either system_id or system_name, and either agent_id or agent_name). Any options not explicitly set in the module call or the playbook will retain their existing values from the current configuration.
22
23 ## Parameters
24
25 ### Required Parameters
26
27 | Parameter | Type | Required | Description |
28 | ---------------- | ---- | -------- | -------------------------------------------------------------------------------------------------- |
29 | `system` | dict | Yes | Dictionary containing system identification. Either `system_id` or `system_name` must be provided. |
30 | `command` | dict | Yes | Definition of the desired command |
31 | `api_connection` | dict | Yes | Connection details for accessing the ALPACA Operator API |
32
33 ### System Identification
34
35 The `system` parameter accepts a dictionary with the following sub-options:
36
37 | Parameter | Type | Required | Description |
38 | ------------- | ---- | -------- | ----------------------------------------------------------------------- |
39 | `system_id` | int | No* | Numeric ID of the target system. Optional if `system_name` is provided. |
40 | `system_name` | str | No* | Name of the target system. Optional if `system_id` is provided. |
41
42 *Either `system_id` or `system_name` must be provided.
43
44 ### Command Configuration
45
46 The `command` parameter accepts a dictionary with the following sub-options:
47
48 | Parameter | Type | Required | Default | Description |
49 | -------------------- | ---- | -------- | ------- | ------------------------------------------------------------------------------------------- |
50 | `name` | str | No | - | Name or description of the command |
51 | `state` | str | No | present | Desired state of the command (present, absent) |
52 | `agent_id` | int | No | - | Numeric ID of the agent. Optional if `agent_name` is provided. |
53 | `agent_name` | str | No | - | Name of the agent. Optional if `agent_id` is provided. |
54 | `process_id` | int | No | - | ID of the process to be executed. Optional if `process_central_id` is provided. |
55 | `process_central_id` | int | No | - | Central ID / Global ID of the process to be executed. Optional if `process_id` is provided. |
56 | `parameters` | str | No | - | Parameters for the process |
57 | `parameters_needed` | bool | No | - | Whether the execution of the command requires additional parameters |
58 | `disabled` | bool | No | - | Whether the command is currently disabled |
59 | `critical` | bool | No | - | Whether the command is marked as critical |
60 | `auto_deploy` | bool | No | - | Whether to automatically deploy the command |
61
62 ### Schedule Configuration
63
64 The `schedule` parameter accepts a dictionary with the following sub-options:
65
66 | Parameter | Type | Required | Description |
67 | ----------------- | ---- | -------- | ----------------------------------------------------------------------------------------------------------------------- |
68 | `period` | str | No | Scheduling period |
69 | `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' |
70 | `cron_expression` | str | No | Quartz-compatible cron expression. Required when period is 'cron_expression' |
71 | `days_of_week` | list | No | List of weekdays for execution |
72
73 **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
74
75 **Days of Week Choices**: monday, tuesday, wednesday, thursday, friday, saturday, sunday
76
77 ### History Configuration
78
79 The `history` parameter accepts a dictionary with the following sub-options:
80
81 | Parameter | Type | Required | Description |
82 | ------------------- | ---- | -------- | ---------------------------------- |
83 | `document_all_runs` | bool | No | Whether to document all executions |
84 | `retention` | int | No | Retention time in seconds |
85
86 ### Timeout Configuration
87
88 The `timeout` parameter accepts a dictionary with the following sub-options:
89
90 | Parameter | Type | Required | Description |
91 | --------- | ---- | -------- | ------------------------------------------ |
92 | `type` | str | No | Type of timeout (none, default, or custom) |
93 | `value` | int | No | Timeout value in seconds (for custom type) |
94
95 **Type Choices**: none, default, custom
96
97 ### Escalation Configuration
98
99 The `escalation` parameter accepts a dictionary with the following sub-options:
100
101 | Parameter | Type | Required | Description |
102 | ------------------- | ---- | -------- | -------------------------------------------- |
103 | `mail_enabled` | bool | No | Whether email alerts are enabled |
104 | `sms_enabled` | bool | No | Whether SMS alerts are enabled |
105 | `mail_address` | str | No | Email address for alerts |
106 | `sms_address` | str | No | SMS number for alerts |
107 | `min_failure_count` | int | No | Minimum number of failures before escalation |
108 | `triggers` | dict | No | Trigger types for escalation |
109
110 ### Escalation Triggers
111
112 The `triggers` parameter accepts a dictionary with the following sub-options:
113
114 | Parameter | Type | Required | Description |
115 | -------------- | ---- | -------- | ---------------------------------- |
116 | `every_change` | bool | No | Currently no description available |
117 | `to_red` | bool | No | Currently no description available |
118 | `to_yellow` | bool | No | Currently no description available |
119 | `to_green` | bool | No | Currently no description available |
120
121 ### API Connection Configuration
122
123 The `api_connection` parameter requires a dictionary with the following sub-options:
124
125 | Parameter | Type | Required | Default | Description |
126 | ------------ | ---- | -------- | --------- | ----------------------------------------------------------- |
127 | `username` | str | Yes | - | Username for authentication against the ALPACA Operator API |
128 | `password` | str | Yes | - | Password for authentication against the ALPACA Operator API |
129 | `protocol` | str | No | https | Protocol to use (http or https) |
130 | `host` | str | No | localhost | Hostname of the ALPACA Operator server |
131 | `port` | int | No | 8443 | Port of the ALPACA Operator API |
132 | `tls_verify` | bool | No | true | Validate SSL certificates |
133
134 ## Examples
135
136 ### Create a Command
137
138 ```yaml
139 - name: Ensure a specific system command exist
140 hosts: local
141 gather_facts: false
142
143 vars:
144 api_connection:
145 host: "{{ ALPACA_Operator_API_Host }}"
146 protocol: "{{ ALPACA_Operator_API_Protocol }}"
147 port: "{{ ALPACA_Operator_API_Port }}"
148 username: "{{ ALPACA_Operator_API_Username }}"
149 password: "{{ ALPACA_Operator_API_Password }}"
150 tls_verify: "{{ ALPACA_Operator_API_Validate_Certs }}"
151
152 tasks:
153 - name: Create command
154 pcg.alpaca_operator.alpaca_command:
155 system:
156 system_name: system01
157 command:
158 name: "BKP: DB log sync"
159 state: present
160 agent_name: agent01
161 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"
162 process_central_id: 8990048
163 schedule:
164 period: manually
165 time: "01:00:00"
166 days_of_week:
167 - monday
168 - sunday
169 parameters_needed: false
170 disabled: false
171 critical: true
172 history:
173 document_all_runs: true
174 retention: 900
175 auto_deploy: false
176 timeout:
177 type: default
178 value: 30
179 escalation:
180 mail_enabled: true
181 sms_enabled: true
182 mail_address: "[email protected]"
183 sms_address: "0123456789"
184 min_failure_count: 1
185 triggers:
186 every_change: true
187 to_red: false
188 to_yellow: false
189 to_green: true
190 api_connection: "{{ api_connection }}"
191 ```
192
193 ### Delete a Command
194
195 ```yaml
196 - name: Delete a specific command
197 hosts: local
198 gather_facts: false
199
200 vars:
201 api_connection:
202 host: "{{ ALPACA_Operator_API_Host }}"
203 protocol: "{{ ALPACA_Operator_API_Protocol }}"
204 port: "{{ ALPACA_Operator_API_Port }}"
205 username: "{{ ALPACA_Operator_API_Username }}"
206 password: "{{ ALPACA_Operator_API_Password }}"
207 tls_verify: "{{ ALPACA_Operator_API_Validate_Certs }}"
208
209 tasks:
210 - name: Delete command
211 pcg.alpaca_operator.alpaca_command:
212 system:
213 system_name: system01
214 command:
215 name: "BKP: DB log sync"
216 agent_name: agent01
217 state: absent
218 api_connection: "{{ api_connection }}"
219 ```
220
221 ## Return Values
222
223 | Parameter | Type | Returned | Description |
224 | --------- | ---- | ----------------------------------------- | ------------------------------------------------------------------------------------------- |
225 | `msg` | str | always | Status message describing what the module did |
226 | `changed` | bool | always | Whether any changes were made |
227 | `changes` | dict | when changes are detected | Dictionary containing the differences between the current and desired command configuration |
228 | `payload` | dict | when state is present and change occurred | Full payload that would be sent to the API (in check_mode) or that was sent (when changed) |
229
230 ### Return Value Examples
231
232 #### Command Update with Changes
233
234 ```json
235 {
236 "msg": "Command updated in system 42.",
237 "changed": true,
238 "changes": {
239 "parameters": {
240 "current": "-p foo -s A -d B",
241 "desired": "-p foo -s A -d B -t X"
242 },
243 "schedule": {
244 "period": {
245 "current": "manually",
246 "desired": "every_minute"
247 }
248 },
249 "escalation": {
250 "min_failure_count": {
251 "current": 0,
252 "desired": 1
253 }
254 }
255 }
256 }
257 ```
258
259 ## Notes
260
261 - The module supports check mode for previewing changes without applying them
262 - Commands are uniquely identified by name and agent assignment
263 - Renaming commands or reassigning to different agents is not supported
264 - When updating existing commands, only specified fields are modified
265 - The agent must be assigned to the corresponding system if managed via Ansible
266 - Schedule configurations support various periodic execution patterns
267 - Escalation settings can be configured for both email and SMS notifications
268 - API connection variables should be stored in the inventory file and referenced via `api_connection: "{{ api_connection }}"` in playbooks
269
270 ## Author
271
272 - Jan-Karsten Hansmeyer (@pcg)