| 1 |
# ALPACA Agent Module |
| 2 |
|
| 3 |
## Overview |
| 4 |
|
| 5 |
The `pcg.alpaca_operator.alpaca_agent` module allows you to create, update, or delete [ALPACA Operator](https://alpaca.pcg.io/) agents using the REST API. This module provides comprehensive management capabilities for ALPACA Operator agents, including configuration of escalation settings, location settings, and other agent-specific properties. |
| 6 |
|
| 7 |
## Module Information |
| 8 |
|
| 9 |
- **Module Name**: `pcg.alpaca_operator.alpaca_agent` |
| 10 |
- **Short Description**: Manage ALPACA Operator agents via REST API |
| 11 |
- **Version Added**: 1.0.0 |
| 12 |
- **Requirements**: |
| 13 |
- Python >= 3.9 |
| 14 |
- ansible-core >= 2.12 |
| 15 |
- ALPACA Operator >= 5.6.0 |
| 16 |
|
| 17 |
## Parameters |
| 18 |
|
| 19 |
### Required Parameters |
| 20 |
|
| 21 |
| Parameter | Type | Required | Description | |
| 22 |
| ---------------- | ---- | -------- | -------------------------------------------------------- | |
| 23 |
| `name` | str | Yes | Unique name (hostname) of the agent | |
| 24 |
| `api_connection` | dict | Yes | Connection details for accessing the ALPACA Operator API | |
| 25 |
|
| 26 |
### Optional Parameters |
| 27 |
|
| 28 |
| Parameter | Type | Required | Default | Description | |
| 29 |
| ----------------- | ---- | -------- | ------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
| 30 |
| `new_name` | str | No | - | Optional new name for the agent. If the agent specified in `name` exists, it will be renamed to this value. If the agent does not exist, a new agent will be created using this value. | |
| 31 |
| `description` | str | No | - | Unique description of the agent | |
| 32 |
| `escalation` | dict | No | - | Escalation configuration | |
| 33 |
| `ip_address` | str | No | - | IP address of the agent | |
| 34 |
| `location` | str | No | virtual | Location of the agent (virtual, local1, local2, remote) | |
| 35 |
| `script_group_id` | int | No | -1 | Script Group ID | |
| 36 |
| `state` | str | No | present | Desired state of the agent (present, absent) | |
| 37 |
|
| 38 |
### Escalation Configuration |
| 39 |
|
| 40 |
The `escalation` parameter accepts a dictionary with the following sub-options: |
| 41 |
|
| 42 |
| Parameter | Type | Required | Default | Description | |
| 43 |
| ------------------------ | ---- | -------- | ------- | ------------------------------------ | |
| 44 |
| `failures_before_report` | int | No | 0 | Number of failures before reporting | |
| 45 |
| `mail_enabled` | bool | No | false | Whether mail notification is enabled | |
| 46 |
| `mail_address` | str | No | "" | Mail address for notifications | |
| 47 |
| `sms_enabled` | bool | No | false | Whether SMS notification is enabled | |
| 48 |
| `sms_address` | str | No | "" | SMS address for notifications | |
| 49 |
|
| 50 |
### API Connection Configuration |
| 51 |
|
| 52 |
The `api_connection` parameter requires a dictionary with the following sub-options: |
| 53 |
|
| 54 |
| Parameter | Type | Required | Default | Description | |
| 55 |
| ------------ | ---- | -------- | --------- | ----------------------------------------------------------- | |
| 56 |
| `username` | str | Yes | - | Username for authentication against the ALPACA Operator API | |
| 57 |
| `password` | str | Yes | - | Password for authentication against the ALPACA Operator API | |
| 58 |
| `protocol` | str | No | https | Protocol to use (http or https) | |
| 59 |
| `host` | str | No | localhost | Hostname of the ALPACA Operator server | |
| 60 |
| `port` | int | No | 8443 | Port of the ALPACA Operator API | |
| 61 |
| `tls_verify` | bool | No | true | Validate SSL certificates | |
| 62 |
|
| 63 |
## Examples |
| 64 |
|
| 65 |
### Create an Agent |
| 66 |
|
| 67 |
```yaml |
| 68 |
- name: Ensure agent exists |
| 69 |
hosts: local |
| 70 |
gather_facts: false |
| 71 |
|
| 72 |
vars: |
| 73 |
api_connection: |
| 74 |
host: "{{ ALPACA_Operator_API_Host }}" |
| 75 |
protocol: "{{ ALPACA_Operator_API_Protocol }}" |
| 76 |
port: "{{ ALPACA_Operator_API_Port }}" |
| 77 |
username: "{{ ALPACA_Operator_API_Username }}" |
| 78 |
password: "{{ ALPACA_Operator_API_Password }}" |
| 79 |
tls_verify: "{{ ALPACA_Operator_API_Validate_Certs }}" |
| 80 |
|
| 81 |
tasks: |
| 82 |
- name: Create agent |
| 83 |
pcg.alpaca_operator.alpaca_agent: |
| 84 |
name: agent01 |
| 85 |
ip_address: 192.168.1.100 |
| 86 |
location: virtual |
| 87 |
description: Test agent |
| 88 |
escalation: |
| 89 |
failures_before_report: 3 |
| 90 |
mail_enabled: true |
| 91 |
mail_address: [email protected] |
| 92 |
sms_enabled: true |
| 93 |
sms_address: 0123456789 |
| 94 |
script_group_id: 0 |
| 95 |
state: present |
| 96 |
api_connection: "{{ api_connection }}" |
| 97 |
``` |
| 98 |
|
| 99 |
### Delete an Agent |
| 100 |
|
| 101 |
```yaml |
| 102 |
- name: Ensure agent is absent |
| 103 |
hosts: local |
| 104 |
gather_facts: false |
| 105 |
|
| 106 |
vars: |
| 107 |
api_connection: |
| 108 |
host: "{{ ALPACA_Operator_API_Host }}" |
| 109 |
protocol: "{{ ALPACA_Operator_API_Protocol }}" |
| 110 |
port: "{{ ALPACA_Operator_API_Port }}" |
| 111 |
username: "{{ ALPACA_Operator_API_Username }}" |
| 112 |
password: "{{ ALPACA_Operator_API_Password }}" |
| 113 |
tls_verify: "{{ ALPACA_Operator_API_Validate_Certs }}" |
| 114 |
|
| 115 |
tasks: |
| 116 |
- name: Delete agent |
| 117 |
pcg.alpaca_operator.alpaca_agent: |
| 118 |
name: agent01 |
| 119 |
state: absent |
| 120 |
api_connection: "{{ api_connection }}" |
| 121 |
``` |
| 122 |
|
| 123 |
### Rename an Agent |
| 124 |
|
| 125 |
```yaml |
| 126 |
- name: Rename an existing agent |
| 127 |
hosts: local |
| 128 |
gather_facts: false |
| 129 |
|
| 130 |
vars: |
| 131 |
api_connection: |
| 132 |
host: "{{ ALPACA_Operator_API_Host }}" |
| 133 |
protocol: "{{ ALPACA_Operator_API_Protocol }}" |
| 134 |
port: "{{ ALPACA_Operator_API_Port }}" |
| 135 |
username: "{{ ALPACA_Operator_API_Username }}" |
| 136 |
password: "{{ ALPACA_Operator_API_Password }}" |
| 137 |
tls_verify: "{{ ALPACA_Operator_API_Validate_Certs }}" |
| 138 |
|
| 139 |
tasks: |
| 140 |
- name: Rename agent |
| 141 |
pcg.alpaca_operator.alpaca_agent: |
| 142 |
name: agent01 |
| 143 |
new_name: agent_renamed |
| 144 |
state: present |
| 145 |
api_connection: "{{ api_connection }}" |
| 146 |
``` |
| 147 |
|
| 148 |
## Return Values |
| 149 |
|
| 150 |
| Parameter | Type | Returned | Description | |
| 151 |
| -------------- | ---- | ------------------------------------------- | ---------------------------------------------------------------------------- | |
| 152 |
| `msg` | str | always | Status message indicating the result of the operation | |
| 153 |
| `changed` | bool | always | Indicates whether any change was made | |
| 154 |
| `agent_config` | dict | when state is present or absent | Details of the created, updated, or deleted agent configuration | |
| 155 |
| `changes` | dict | when state is present and a change occurred | Dictionary showing differences between the current and desired configuration | |
| 156 |
|
| 157 |
### Return Value Examples |
| 158 |
|
| 159 |
#### Successful Agent Creation |
| 160 |
|
| 161 |
```json |
| 162 |
{ |
| 163 |
"msg": "Agent created", |
| 164 |
"changed": true, |
| 165 |
"agent_config": { |
| 166 |
"id": 7, |
| 167 |
"hostname": "testagent", |
| 168 |
"description": "Test agent", |
| 169 |
"ip_address": "10.1.1.1", |
| 170 |
"location": "virtual", |
| 171 |
"script_group_id": 2, |
| 172 |
"escalation": { |
| 173 |
"failures_before_report": 3, |
| 174 |
"mail_enabled": true, |
| 175 |
"mail_address": "[email protected]", |
| 176 |
"sms_enabled": false, |
| 177 |
"sms_address": "" |
| 178 |
} |
| 179 |
} |
| 180 |
} |
| 181 |
``` |
| 182 |
|
| 183 |
#### Agent Update with Changes |
| 184 |
|
| 185 |
```json |
| 186 |
{ |
| 187 |
"msg": "Agent updated", |
| 188 |
"changed": true, |
| 189 |
"changes": { |
| 190 |
"ip_address": { |
| 191 |
"current": "10.1.1.1", |
| 192 |
"desired": "10.1.1.2" |
| 193 |
}, |
| 194 |
"escalation": { |
| 195 |
"mail_enabled": { |
| 196 |
"current": false, |
| 197 |
"desired": true |
| 198 |
} |
| 199 |
} |
| 200 |
} |
| 201 |
} |
| 202 |
``` |
| 203 |
|
| 204 |
## Notes |
| 205 |
|
| 206 |
- The module supports check mode for previewing changes without applying them |
| 207 |
- Agent names must be unique within the ALPACA Operator environment |
| 208 |
- When renaming an agent, the new name must not conflict with existing agent names |
| 209 |
- Escalation settings are optional and can be configured independently |
| 210 |
- The `script_group_id` parameter defaults to -1 if not specified |
| 211 |
- Location options include: virtual, local1, local2, remote |
| 212 |
- API connection variables should be stored in the inventory file and referenced via `api_connection: "{{ api_connection }}"` in playbooks |
| 213 |
|
| 214 |
## Author |
| 215 |
|
| 216 |
- Jan-Karsten Hansmeyer (@pcg) |