| 1 |
# ALPACA Group Module |
| 2 |
|
| 3 |
## Overview |
| 4 |
|
| 5 |
The `pcg.alpaca_operator.alpaca_group` module allows you to create, rename, or delete [ALPACA Operator](https://alpaca.pcg.io/) groups using the REST API. This module provides basic group management capabilities for organizing systems within the ALPACA Operator environment. |
| 6 |
|
| 7 |
## Module Information |
| 8 |
|
| 9 |
- **Module Name**: `pcg.alpaca_operator.alpaca_group` |
| 10 |
- **Short Description**: Manage ALPACA Operator groups 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 | Name of the group | |
| 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 group. If the group specified in `name` exists, it will be renamed to this value. If the group does not exist, a new group will be created using this value. | |
| 31 |
| `state` | str | No | present | Desired state of the group (present, absent) | |
| 32 |
|
| 33 |
### API Connection Configuration |
| 34 |
|
| 35 |
The `api_connection` parameter requires a dictionary with the following sub-options: |
| 36 |
|
| 37 |
| Parameter | Type | Required | Default | Description | |
| 38 |
| ------------ | ---- | -------- | --------- | ----------------------------------------------------------- | |
| 39 |
| `username` | str | Yes | - | Username for authentication against the ALPACA Operator API | |
| 40 |
| `password` | str | Yes | - | Password for authentication against the ALPACA Operator API | |
| 41 |
| `protocol` | str | No | https | Protocol to use (http or https) | |
| 42 |
| `host` | str | No | localhost | Hostname of the ALPACA Operator server | |
| 43 |
| `port` | int | No | 8443 | Port of the ALPACA Operator API | |
| 44 |
| `tls_verify` | bool | No | true | Validate SSL certificates | |
| 45 |
|
| 46 |
## Examples |
| 47 |
|
| 48 |
### Create a Group |
| 49 |
|
| 50 |
```yaml |
| 51 |
- name: Ensure group exists |
| 52 |
hosts: local |
| 53 |
gather_facts: false |
| 54 |
|
| 55 |
vars: |
| 56 |
api_connection: |
| 57 |
host: "{{ ALPACA_Operator_API_Host }}" |
| 58 |
protocol: "{{ ALPACA_Operator_API_Protocol }}" |
| 59 |
port: "{{ ALPACA_Operator_API_Port }}" |
| 60 |
username: "{{ ALPACA_Operator_API_Username }}" |
| 61 |
password: "{{ ALPACA_Operator_API_Password }}" |
| 62 |
tls_verify: "{{ ALPACA_Operator_API_Validate_Certs }}" |
| 63 |
|
| 64 |
tasks: |
| 65 |
- name: Create group |
| 66 |
pcg.alpaca_operator.alpaca_group: |
| 67 |
name: testgroup01 |
| 68 |
state: present |
| 69 |
api_connection: "{{ api_connection }}" |
| 70 |
``` |
| 71 |
|
| 72 |
### Delete a Group |
| 73 |
|
| 74 |
```yaml |
| 75 |
- name: Ensure group is absent |
| 76 |
hosts: local |
| 77 |
gather_facts: false |
| 78 |
|
| 79 |
vars: |
| 80 |
api_connection: |
| 81 |
host: "{{ ALPACA_Operator_API_Host }}" |
| 82 |
protocol: "{{ ALPACA_Operator_API_Protocol }}" |
| 83 |
port: "{{ ALPACA_Operator_API_Port }}" |
| 84 |
username: "{{ ALPACA_Operator_API_Username }}" |
| 85 |
password: "{{ ALPACA_Operator_API_Password }}" |
| 86 |
tls_verify: "{{ ALPACA_Operator_API_Validate_Certs }}" |
| 87 |
|
| 88 |
tasks: |
| 89 |
- name: Delete group |
| 90 |
pcg.alpaca_operator.alpaca_group: |
| 91 |
name: testgroup01 |
| 92 |
state: absent |
| 93 |
api_connection: "{{ api_connection }}" |
| 94 |
``` |
| 95 |
|
| 96 |
### Rename a Group |
| 97 |
|
| 98 |
```yaml |
| 99 |
- name: Rename an existing group |
| 100 |
hosts: local |
| 101 |
gather_facts: false |
| 102 |
|
| 103 |
vars: |
| 104 |
api_connection: |
| 105 |
host: "{{ ALPACA_Operator_API_Host }}" |
| 106 |
protocol: "{{ ALPACA_Operator_API_Protocol }}" |
| 107 |
port: "{{ ALPACA_Operator_API_Port }}" |
| 108 |
username: "{{ ALPACA_Operator_API_Username }}" |
| 109 |
password: "{{ ALPACA_Operator_API_Password }}" |
| 110 |
tls_verify: "{{ ALPACA_Operator_API_Validate_Certs }}" |
| 111 |
|
| 112 |
tasks: |
| 113 |
- name: Rename group |
| 114 |
pcg.alpaca_operator.alpaca_group: |
| 115 |
name: testgroup01 |
| 116 |
new_name: testgroup_renamed |
| 117 |
state: present |
| 118 |
api_connection: "{{ api_connection }}" |
| 119 |
``` |
| 120 |
|
| 121 |
## Return Values |
| 122 |
|
| 123 |
| Parameter | Type | Returned | Description | |
| 124 |
| --------- | ---- | ------------------------------------------------ | --------------------------------------------------- | |
| 125 |
| `changed` | bool | always | Indicates whether any change was made to the group | |
| 126 |
| `msg` | str | always | Human-readable message describing the outcome | |
| 127 |
| `id` | int | when state is present or absent and group exists | Numeric ID of the group (if known or newly created) | |
| 128 |
| `name` | str | always | Name of the group (new or existing) | |
| 129 |
|
| 130 |
### Return Value Examples |
| 131 |
|
| 132 |
#### Successful Group Creation |
| 133 |
|
| 134 |
```json |
| 135 |
{ |
| 136 |
"changed": true, |
| 137 |
"msg": "Group created", |
| 138 |
"id": 42, |
| 139 |
"name": "testgroup01" |
| 140 |
} |
| 141 |
``` |
| 142 |
|
| 143 |
#### Group Already Exists |
| 144 |
|
| 145 |
```json |
| 146 |
{ |
| 147 |
"changed": false, |
| 148 |
"msg": "Group already exists", |
| 149 |
"id": 42, |
| 150 |
"name": "testgroup01" |
| 151 |
} |
| 152 |
``` |
| 153 |
|
| 154 |
#### Group Renamed |
| 155 |
|
| 156 |
```json |
| 157 |
{ |
| 158 |
"changed": true, |
| 159 |
"msg": "Group renamed", |
| 160 |
"id": 42, |
| 161 |
"name": "testgroup_renamed" |
| 162 |
} |
| 163 |
``` |
| 164 |
|
| 165 |
#### Group Deleted |
| 166 |
|
| 167 |
```json |
| 168 |
{ |
| 169 |
"changed": true, |
| 170 |
"msg": "Group deleted", |
| 171 |
"name": "testgroup01" |
| 172 |
} |
| 173 |
``` |
| 174 |
|
| 175 |
## Notes |
| 176 |
|
| 177 |
- The module supports check mode for previewing changes without applying them |
| 178 |
- Group names must be unique within the ALPACA Operator environment |
| 179 |
- When renaming a group, the new name must not conflict with existing group names |
| 180 |
- The module will create a new group if the specified name doesn't exist and `new_name` is provided |
| 181 |
- Groups can be used to organize systems within the ALPACA Operator environment |
| 182 |
- The module uses token-based authentication for API communication |
| 183 |
- API connection variables should be stored in the inventory file and referenced via `api_connection: "{{ api_connection }}"` in playbooks |
| 184 |
|
| 185 |
## Author |
| 186 |
|
| 187 |
- Jan-Karsten Hansmeyer (@pcg) |