Commit 6cd06ce
committed
e162cf1 fix: [#105] improve error mapping for context creation failures (copilot-swe-agent[bot])
b61ffea fix: [#105] remove Tera variables from comments in template (copilot-swe-agent[bot])
57c357d fix: [#105] fix clippy warnings and formatting (copilot-swe-agent[bot])
dae5fa0 feat: [#105] integrate variables rendering into AnsibleTemplateRenderer (copilot-swe-agent[bot])
5976b7c feat: [#105] add VariablesTemplateRenderer (copilot-swe-agent[bot])
b411b6d feat: [#105] add AnsibleVariablesTemplate wrapper (copilot-swe-agent[bot])
a033f0d feat: [#105] add AnsibleVariablesContext with validation (copilot-swe-agent[bot])
8759e57 feat: [#105] add centralized variables template file (copilot-swe-agent[bot])
bff5db0 Initial plan (copilot-swe-agent[bot])
Pull request description:
Implements the foundational infrastructure for consolidating Ansible playbook variables into a centralized `variables.yml` file, following the same pattern as OpenTofu's `variables.tfvars.tera`.
## Implementation
### Template & Context
- **Template**: `templates/ansible/variables.yml.tera` - Centralized variable definitions with SSH port
- **Context**: `AnsibleVariablesContext` - Validates SSH port using existing `AnsiblePort` validation
### Wrapper & Renderer
- **Wrapper**: `AnsibleVariablesTemplate` - Renders template with domain `TemplateEngine`
- **Renderer**: `VariablesTemplateRenderer` - Orchestrates template loading, context processing, and file output
- **Integration**: Hooked into `AnsibleTemplateRenderer::render()` workflow after firewall playbook rendering
### Error Handling
- Added `ContextCreationFailed` error variant for SSH port validation failures
- Updated both `create_firewall_context()` and `create_variables_context()` to use semantically correct error types
## Output
Generated `variables.yml` contains runtime SSH port configuration:
```yaml
---
# Centralized Ansible Variables
ssh_port: 22
# Future service variables can be added here when needed
```
## Architecture
Follows existing three-layer template pattern:
1. **Context Layer** - Validates input data (SSH port)
2. **Wrapper Layer** - Renders Tera template with validated context
3. **Renderer Layer** - Orchestrates file I/O and template management
Future service variables (MySQL, Tracker, Prometheus, Grafana) can be added to the template without additional Rust infrastructure per service.
<!-- START COPILOT CODING AGENT SUFFIX -->
<details>
<summary>Original prompt</summary>
>
> ----
>
> *This section details on the original issue you should resolve*
>
> <issue_title>Create Variables Template Infrastructure</issue_title>
> <issue_description>**Parent Epic**: #19 - Refactor Ansible Templates to Variables Pattern
>
> ## Overview
>
> Create the centralized `variables.yml.tera` template and supporting Rust infrastructure (context, wrapper, renderer) to consolidate Ansible playbook variables into a single file. This establishes the foundation for the variables pattern that will simplify future playbook additions.
>
> ## Goals
>
> - [ ] **Variables Template**: Create `templates/ansible/variables.yml.tera` with system configuration variables
> - [ ] **Context Layer**: Implement `AnsibleVariablesContext` with validation
> - [ ] **Wrapper Layer**: Implement `AnsibleVariablesTemplate` for rendering
> - [ ] **Renderer Layer**: Implement `VariablesTemplateRenderer` for orchestration
> - [ ] **Integration**: Hook into `AnsibleTemplateRenderer::render()` workflow
> - [ ] **Test Coverage**: Comprehensive unit tests for all components
>
> ## 🏗️ Architecture Requirements
>
> **DDD Layer**: Infrastructure
> **Module Path**: `src/infrastructure/external_tools/ansible/template/`
> **Pattern**: Template Wrapper + Context + Renderer (existing pattern)
>
> ## Time Estimate
>
> **2.5 days** - Complete vertical slice including implementation, testing, and documentation
>
> ## Documentation
>
> Full implementation details: [`docs/issues/19.1-create-variables-template.md`](https://github.com/torrust/torrust-tracker-deployer/blob/copilot/configure-ufw-firewall/docs/issues/19.1-create-variables-template.md)
>
> ## Acceptance Criteria
>
> ### Template File
> - [ ] `templates/ansible/variables.yml.tera` exists with SSH port variable
> - [ ] Template has correct Tera syntax: `{{ ssh_port }}`
> - [ ] YAML linting passes
>
> ### Implementation
> - [ ] `AnsibleVariablesContext` with SSH port validation
> - [ ] `AnsibleVariablesTemplate` wrapper implementation
> - [ ] `VariablesTemplateRenderer` orchestrator
> - [ ] Integration into `AnsibleTemplateRenderer`
>
> ### Testing
> - [ ] Unit tests pass: `cargo test`
> - [ ] Config tests pass: `cargo run --bin e2e-config-tests`
> - [ ] Linters pass: `cargo run --bin linter all`
> - [ ] `variables.yml` generated in build directory
>
> ### Documentation
> - [ ] Rustdoc comments for all public types
> - [ ] Template file includes descriptive comments
> - [ ] Error types have clear descriptions
>
> ## Related
>
> - Parent Epic: #19
> - Next Task: #19.2 (depends on this task)
> - [Template System Architecture](https://github.com/torrust/torrust-tracker-deployer/blob/main/docs/technical/template-system-architecture.md)</issue_description>
>
> ## Comments on the Issue (you are @copilot in this section)
>
> <comments>
> </comments>
>
</details>
- Fixes #105
<!-- START COPILOT CODING AGENT TIPS -->
---
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more [Copilot coding agent tips](https://gh.io/copilot-coding-agent-tips) in the docs.
ACKs for top commit:
josecelano:
ACK e162cf1
Tree-SHA512: 7dc3c0b1e16a99eb0ada7881c0f047289f2a50524a4014ced1c5bae3085edbe30a079cca8aff8ecd13481f07987ab06ad7a559ac8ee93b82c2732367bf84daba
File tree
6 files changed
+608
-10
lines changed- src/infrastructure/external_tools/ansible/template
- renderer
- wrappers
- variables
- templates/ansible
6 files changed
+608
-10
lines changedLines changed: 64 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
| 58 | + | |
58 | 59 | | |
59 | 60 | | |
60 | 61 | | |
| 62 | + | |
61 | 63 | | |
62 | 64 | | |
63 | 65 | | |
| |||
129 | 131 | | |
130 | 132 | | |
131 | 133 | | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
132 | 148 | | |
133 | 149 | | |
134 | 150 | | |
| |||
141 | 157 | | |
142 | 158 | | |
143 | 159 | | |
| 160 | + | |
144 | 161 | | |
145 | 162 | | |
146 | 163 | | |
| |||
161 | 178 | | |
162 | 179 | | |
163 | 180 | | |
| 181 | + | |
164 | 182 | | |
165 | 183 | | |
166 | 184 | | |
167 | 185 | | |
168 | 186 | | |
169 | 187 | | |
| 188 | + | |
170 | 189 | | |
171 | 190 | | |
172 | 191 | | |
| |||
219 | 238 | | |
220 | 239 | | |
221 | 240 | | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
222 | 247 | | |
223 | 248 | | |
224 | 249 | | |
| |||
421 | 446 | | |
422 | 447 | | |
423 | 448 | | |
424 | | - | |
425 | | - | |
426 | | - | |
427 | | - | |
428 | | - | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
429 | 452 | | |
430 | 453 | | |
431 | 454 | | |
432 | 455 | | |
433 | 456 | | |
434 | | - | |
435 | | - | |
436 | | - | |
437 | | - | |
438 | | - | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
439 | 493 | | |
440 | 494 | | |
441 | 495 | | |
| |||
0 commit comments