| 1 |
# ALPACA Operator Ansible Collection Documentation |
| 2 |
|
| 3 |
## Overview |
| 4 |
|
| 5 |
The ALPACA Operator Ansible Collection provides a comprehensive set of modules for managing [ALPACA Operator](https://alpaca.pcg.io/) environments through Ansible automation. This collection enables you to manage agents, systems, groups, commands, and command sets using the ALPACA Operator REST API. |
| 6 |
|
| 7 |
## Modules |
| 8 |
|
| 9 |
### Core Management Modules |
| 10 |
|
| 11 |
| Module | Description | Use Case | |
| 12 |
| ------------------------------------------------------- | ------------------------------ | ------------------------------------------------------------------------------------- | |
| 13 |
| [`pcg.alpaca_operator.alpaca_agent`](alpaca_agent.md) | Manage ALPACA Operator agents | Create, update, delete, and configure agents with escalation settings | |
| 14 |
| [`pcg.alpaca_operator.alpaca_system`](alpaca_system.md) | Manage ALPACA Operator systems | Create, update, delete systems with RFC connections, agent assignments, and variables | |
| 15 |
| [`pcg.alpaca_operator.alpaca_group`](alpaca_group.md) | Manage ALPACA Operator groups | Create, rename, and delete groups for organizing systems | |
| 16 |
|
| 17 |
### Command Management Modules |
| 18 |
|
| 19 |
| Module | Description | Use Case | |
| 20 |
| ----------------------------------------------------------------- | ------------------------------------------ | -------------------------------------------------------- | |
| 21 |
| [`pcg.alpaca_operator.alpaca_command`](alpaca_command.md) | Manage individual ALPACA Operator commands | Fine-grained control over single command properties | |
| 22 |
| [`pcg.alpaca_operator.alpaca_command_set`](alpaca_command_set.md) | Manage command sets for systems | Bulk management of all commands associated with a system | |
| 23 |
|
| 24 |
## Installation |
| 25 |
|
| 26 |
### Prerequisites |
| 27 |
|
| 28 |
- SLES 15 SP4 or later (or compatible Linux distribution) |
| 29 |
- Python >= 3.9 |
| 30 |
- ansible-core >= 2.12 |
| 31 |
- ALPACA Operator >= 5.6.0 |
| 32 |
- Root or sudo access for system-level installation |
| 33 |
- Internet connectivity for package installation |
| 34 |
|
| 35 |
### Step 1: Check Python Version |
| 36 |
|
| 37 |
First, determine your Python version to select the appropriate Ansible version: |
| 38 |
|
| 39 |
```bash |
| 40 |
ls /usr/bin/python* |
| 41 |
python3 --version |
| 42 |
``` |
| 43 |
|
| 44 |
Refer to the [Support Matrix](../README.md#support-matrix) in the main README to determine which Ansible version is compatible with your Python version. |
| 45 |
|
| 46 |
### Step 2: Install Ansible |
| 47 |
|
| 48 |
#### Option A: Install via Zypper (Recommended for SLES) |
| 49 |
|
| 50 |
```bash |
| 51 |
# Add the Ansible repository |
| 52 |
sudo zypper addrepo https://download.opensuse.org/repositories/systemsmanagement:/ansible/SLE_15_SP4/ ansible |
| 53 |
|
| 54 |
# Refresh repositories |
| 55 |
sudo zypper refresh |
| 56 |
|
| 57 |
# Install Ansible (replace X.Y with your chosen version, e.g., 2.17) |
| 58 |
sudo zypper install ansible-2.17 |
| 59 |
``` |
| 60 |
|
| 61 |
#### Option B: Install via pip |
| 62 |
|
| 63 |
```bash |
| 64 |
# Install pip if not available |
| 65 |
sudo zypper install python3-pip |
| 66 |
|
| 67 |
# Install specific Ansible version (replace X.Y.Z with your chosen version) |
| 68 |
pip3 install ansible==2.17.0 |
| 69 |
``` |
| 70 |
|
| 71 |
#### Verify Installation |
| 72 |
|
| 73 |
```bash |
| 74 |
ansible --version |
| 75 |
``` |
| 76 |
|
| 77 |
### Step 3: Install ALPACA Operator Collection |
| 78 |
|
| 79 |
#### Option A: Install from Ansible Galaxy (Recommended) |
| 80 |
|
| 81 |
```bash |
| 82 |
ansible-galaxy collection install pcg.alpaca_operator |
| 83 |
``` |
| 84 |
|
| 85 |
#### Option B: Install from Git Repository |
| 86 |
|
| 87 |
```bash |
| 88 |
ansible-galaxy collection install git+https://github.com/pcg-sap/alpaca-operator-ansible.git |
| 89 |
``` |
| 90 |
|
| 91 |
#### Option C: Manual Installation from Release |
| 92 |
|
| 93 |
1. Download the latest release from [GitHub Releases](https://github.com/pcg-sap/alpaca-operator-ansible/releases) |
| 94 |
2. Copy the release archive to your server |
| 95 |
3. Extract the archive |
| 96 |
4. Change to the extracted directory |
| 97 |
5. Install the collection: |
| 98 |
|
| 99 |
```bash |
| 100 |
# Navigate to the extracted directory |
| 101 |
cd alpaca-operator-ansible-* |
| 102 |
|
| 103 |
# Install the collection (optional use --force to overwrite existing installation) |
| 104 |
ansible-galaxy collection install ./ --force |
| 105 |
|
| 106 |
# Verify collection was installed |
| 107 |
ansible-galaxy collection list |
| 108 |
``` |
| 109 |
|
| 110 |
**Note**: If you installed the collection manually, the path might be different. Adjust the path to where you extracted the collection. |
| 111 |
|
| 112 |
## Getting Started |
| 113 |
|
| 114 |
### Step 1: Create Project Directory |
| 115 |
|
| 116 |
Create a working directory for your Ansible automation: |
| 117 |
|
| 118 |
```bash |
| 119 |
mkdir -p ~/alpaca-ansible-automation |
| 120 |
cd ~/alpaca-ansible-automation |
| 121 |
``` |
| 122 |
|
| 123 |
### Step 2: Configure Ansible |
| 124 |
|
| 125 |
Create an Ansible configuration file: |
| 126 |
|
| 127 |
```bash |
| 128 |
cat > ansible.cfg << 'EOF' |
| 129 |
[defaults] |
| 130 |
inventory = ./inventory.ini |
| 131 |
host_key_checking = False |
| 132 |
EOF |
| 133 |
``` |
| 134 |
|
| 135 |
### Step 3: Create Inventory |
| 136 |
|
| 137 |
Create an inventory file with your ALPACA API configuration: |
| 138 |
|
| 139 |
```bash |
| 140 |
cat > inventory.ini << 'EOF' |
| 141 |
[local] |
| 142 |
localhost ansible_connection=local |
| 143 |
|
| 144 |
[local:vars] |
| 145 |
ansible_python_interpreter=/usr/bin/python3 |
| 146 |
|
| 147 |
# ALPACA API Configuration |
| 148 |
ALPACA_Operator_API_Host='localhost' |
| 149 |
ALPACA_Operator_API_Protocol='https' |
| 150 |
ALPACA_Operator_API_Port='8443' |
| 151 |
ALPACA_Operator_API_Username='<username>' |
| 152 |
ALPACA_Operator_API_Password='<password>' |
| 153 |
ALPACA_Operator_API_Validate_Certs=False |
| 154 |
EOF |
| 155 |
``` |
| 156 |
|
| 157 |
**Important Notes:** |
| 158 |
- Customize API username and password according to your environment |
| 159 |
- If you have multiple Python versions installed, specify the exact interpreter path |
| 160 |
- Available Python versions can be checked with: `ls /usr/bin/python*` |
| 161 |
- Avoid using generic `python3` if multiple Python 3.x versions are installed |
| 162 |
|
| 163 |
**Python interpreter examples:** |
| 164 |
- `/usr/bin/python3.9` - Python 3.9 |
| 165 |
- `/usr/bin/python3.10` - Python 3.10 |
| 166 |
- `/usr/bin/python3.11` - Python 3.11 |
| 167 |
- `/usr/bin/python3.12` - Python 3.12 |
| 168 |
|
| 169 |
### Step 4: Test ALPACA API Connection |
| 170 |
|
| 171 |
Create and run a test playbook to verify API connectivity: |
| 172 |
|
| 173 |
```bash |
| 174 |
mkdir playbooks |
| 175 |
cat > playbooks/test_connection.yml << 'EOF' |
| 176 |
--- |
| 177 |
- name: Test ALPACA API Connection |
| 178 |
hosts: local |
| 179 |
gather_facts: false |
| 180 |
|
| 181 |
tasks: |
| 182 |
- name: Test API connection using ALPACA module utilities |
| 183 |
block: |
| 184 |
- name: Import ALPACA API utilities |
| 185 |
ansible.builtin.set_fact: |
| 186 |
api_url: "{{ ALPACA_Operator_API_Protocol }}://{{ ALPACA_Operator_API_Host }}:{{ ALPACA_Operator_API_Port }}/api" |
| 187 |
|
| 188 |
- name: Test authentication and API access |
| 189 |
ansible.builtin.uri: |
| 190 |
url: "{{ api_url }}/auth/login" |
| 191 |
method: POST |
| 192 |
body_format: json |
| 193 |
body: '{"username": "{{ ALPACA_Operator_API_Username }}", "password": "{{ ALPACA_Operator_API_Password }}"}' |
| 194 |
validate_certs: "{{ ALPACA_Operator_API_Validate_Certs }}" |
| 195 |
status_code: [200, 401, 403] |
| 196 |
register: auth_test |
| 197 |
|
| 198 |
- name: Display authentication result |
| 199 |
ansible.builtin.debug: |
| 200 |
msg: "Authentication test: {{ 'SUCCESS' if auth_test.status == 200 else 'FAILED' }} (Status: {{ auth_test.status }})" |
| 201 |
|
| 202 |
- name: Show API token (if authentication successful) |
| 203 |
ansible.builtin.debug: |
| 204 |
msg: "API Token obtained: {{ auth_test.json.token | default('None') | truncate(20, true, '...') }}" |
| 205 |
when: auth_test.status == 200 |
| 206 |
|
| 207 |
rescue: |
| 208 |
- name: Display connection error |
| 209 |
ansible.builtin.debug: |
| 210 |
msg: "Connection failed: {{ ansible_failed_result.msg | default('Unknown error') }}" |
| 211 |
failed_when: true |
| 212 |
|
| 213 |
EOF |
| 214 |
|
| 215 |
# Run the test |
| 216 |
ansible-playbook playbooks/test_connection.yml |
| 217 |
``` |
| 218 |
|
| 219 |
### Step 5: Create Your First Playbook |
| 220 |
|
| 221 |
Create a basic playbook to manage your ALPACA environment: |
| 222 |
|
| 223 |
```yaml |
| 224 |
# playbooks/manage_environment.yml |
| 225 |
--- |
| 226 |
- name: Manage ALPACA Operator Environment |
| 227 |
hosts: local |
| 228 |
gather_facts: false |
| 229 |
|
| 230 |
vars: |
| 231 |
api_connection: |
| 232 |
host: "{{ ALPACA_Operator_API_Host }}" |
| 233 |
protocol: "{{ ALPACA_Operator_API_Protocol }}" |
| 234 |
port: "{{ ALPACA_Operator_API_Port }}" |
| 235 |
username: "{{ ALPACA_Operator_API_Username }}" |
| 236 |
password: "{{ ALPACA_Operator_API_Password }}" |
| 237 |
tls_verify: "{{ ALPACA_Operator_API_Validate_Certs }}" |
| 238 |
|
| 239 |
tasks: |
| 240 |
- name: Create a group |
| 241 |
pcg.alpaca_operator.alpaca_group: |
| 242 |
name: production |
| 243 |
state: present |
| 244 |
api_connection: "{{ api_connection }}" |
| 245 |
|
| 246 |
- name: Create an agent |
| 247 |
pcg.alpaca_operator.alpaca_agent: |
| 248 |
name: backup-agent-01 |
| 249 |
description: Backup Agent for Production |
| 250 |
ip_address: 192.168.1.100 |
| 251 |
location: virtual |
| 252 |
state: present |
| 253 |
api_connection: "{{ api_connection }}" |
| 254 |
``` |
| 255 |
|
| 256 |
### Step 6: Run Your Playbook |
| 257 |
|
| 258 |
Execute the playbook: |
| 259 |
|
| 260 |
```bash |
| 261 |
# Run in check mode first (dry run) with verbosity |
| 262 |
ansible-playbook playbooks/manage_environment.yml --check -v |
| 263 |
|
| 264 |
# Execute the playbook for real deployment |
| 265 |
ansible-playbook playbooks/manage_environment.yml |
| 266 |
``` |
| 267 |
|
| 268 |
## Best Practices |
| 269 |
|
| 270 |
### 1. Use Variables for API Connection |
| 271 |
|
| 272 |
Store your API connection details in the inventory file: |
| 273 |
|
| 274 |
```ini |
| 275 |
# inventories/alpaca.ini |
| 276 |
[local] |
| 277 |
localhost ansible_connection=local ansible_python_interpreter=python3 |
| 278 |
|
| 279 |
[local:vars] |
| 280 |
ALPACA_Operator_API_Host='your-alpaca-server' |
| 281 |
ALPACA_Operator_API_Protocol='https' |
| 282 |
ALPACA_Operator_API_Port='8443' |
| 283 |
ALPACA_Operator_API_Username='your-username' |
| 284 |
ALPACA_Operator_API_Password='your-password' |
| 285 |
ALPACA_Operator_API_Validate_Certs=False |
| 286 |
``` |
| 287 |
|
| 288 |
Then reference them in your playbook: |
| 289 |
|
| 290 |
```yaml |
| 291 |
vars: |
| 292 |
api_connection: |
| 293 |
host: "{{ ALPACA_Operator_API_Host }}" |
| 294 |
protocol: "{{ ALPACA_Operator_API_Protocol }}" |
| 295 |
port: "{{ ALPACA_Operator_API_Port }}" |
| 296 |
username: "{{ ALPACA_Operator_API_Username }}" |
| 297 |
password: "{{ ALPACA_Operator_API_Password }}" |
| 298 |
tls_verify: "{{ ALPACA_Operator_API_Validate_Certs }}" |
| 299 |
``` |
| 300 |
|
| 301 |
### 2. Use Check Mode for Testing |
| 302 |
|
| 303 |
Always test your playbooks in check mode first: |
| 304 |
|
| 305 |
```bash |
| 306 |
ansible-playbook your-playbook.yml --check |
| 307 |
``` |
| 308 |
|
| 309 |
### 3. Organize by Environment |
| 310 |
|
| 311 |
Structure your playbooks to separate different environments: |
| 312 |
|
| 313 |
``` |
| 314 |
playbooks/ |
| 315 |
├── production/ |
| 316 |
│ ├── agents.yml |
| 317 |
│ ├── systems.yml |
| 318 |
│ └── commands.yml |
| 319 |
├── staging/ |
| 320 |
│ ├── agents.yml |
| 321 |
│ ├── systems.yml |
| 322 |
│ └── commands.yml |
| 323 |
└── common/ |
| 324 |
└── groups.yml |
| 325 |
``` |
| 326 |
|
| 327 |
### 4. Enable Verbose Output for Debugging |
| 328 |
|
| 329 |
Use different levels of verbosity when debugging issues: |
| 330 |
|
| 331 |
```bash |
| 332 |
ansible-playbook your-playbook.yml -v # Basic verbose |
| 333 |
ansible-playbook your-playbook.yml -vv # More verbose |
| 334 |
ansible-playbook your-playbook.yml -vvv # Very verbose (debug level) |
| 335 |
``` |
| 336 |
|
| 337 |
### Getting Help |
| 338 |
|
| 339 |
If you encounter issues not covered in this troubleshooting guide: |
| 340 |
|
| 341 |
1. Check the [GitHub Issues](https://github.com/pcg-sap/alpaca-operator-ansible/issues) for similar problems |
| 342 |
2. Review module-specific documentation in the [docs](.) directory |
| 343 |
3. Enable verbose output (`-vvv`) to get detailed error information |
| 344 |
4. Create a new issue with: |
| 345 |
- Ansible version (`ansible --version`) |
| 346 |
- Collection version (`ansible-galaxy collection list pcg.alpaca_operator`) |
| 347 |
- Python version (`python3 --version`) |
| 348 |
- Error message and stack trace |
| 349 |
- Minimal reproducible example |
| 350 |
|
| 351 |
## Support |
| 352 |
|
| 353 |
For issues and questions: |
| 354 |
|
| 355 |
- **GitHub Issues**: [https://github.com/pcg-sap/alpaca-operator-ansible/issues](https://github.com/pcg-sap/alpaca-operator-ansible/issues) |
| 356 |
- **Author**: Jan-Karsten Hansmeyer (@pcg) |
| 357 |
|
| 358 |
## License |
| 359 |
|
| 360 |
Apache License, Version 2.0 |