EPIC: Refactor Ansible Templates to Variables Pattern
Type: EPIC
Parent Epic: #16 - Finish ConfigureCommand - System Security Configuration
Depends On: #18 - Configure UFW Firewall
Overview
This epic tracks the refactoring of Ansible templates to use a centralized variables pattern similar to OpenTofu's variables.tfvars.tera approach. This consolidates multiple Tera templates into a single variables file, reducing complexity and establishing a consistent pattern for future Ansible template additions.
After implementing the security updates and firewall configuration, we now have 2 Tera templates (inventory.yml.tera and configure-firewall.yml.tera). This refactoring consolidates them into a single variables-based approach that will simplify future service additions.
Sub-Tasks
This EPIC uses vertical slice approach - each sub-task is a complete, independently deployable increment:
Goals
Implementation Approach
This epic uses vertical slice methodology - each sub-task is a complete, independently deployable increment that includes implementation, cleanup, documentation, and validation. This follows lean/agile principles rather than waterfall phases.
Vertical Slice 1: Create Variables Template Infrastructure (Estimated: 2.5 days)
Complete increment including:
- Create
templates/ansible/variables.yml.tera template file
- Implement
AnsibleVariablesContext with validation
- Implement
AnsibleVariablesTemplate wrapper
- Implement
VariablesTemplateRenderer orchestrator
- Integrate into
AnsibleTemplateRenderer workflow
- Write unit tests for all components
- Add Rustdoc documentation
- Verify with linters and tests
Outcome: System works with new variables infrastructure in place, fully tested and documented.
See: Issue #105
Vertical Slice 2: Convert Firewall to Variables Pattern (Estimated: 4.5 days)
Complete increment including:
- Convert
configure-firewall.yml.tera → configure-firewall.yml (static)
- Add
vars_files: [variables.yml] to playbook
- Register as static template in
copy_static_templates()
- Update
AnsibleClient to accept extra arguments
- Update all call sites
- Remove firewall renderer from workflow
- Delete old firewall renderer/wrapper code (~500 lines)
- Update template system architecture documentation
- Update contributing templates guide
- Update templates README
- Run full test suite (unit, config, linters)
- Verify build directory structure
- Document E2E test plan for human reviewer
Outcome: System works with firewall using variables pattern, old code removed, documentation updated, all tests passing.
See: Issue #106
Total Estimated Time: 7 days (2.5 + 4.5)
Dependencies
High-Level Architecture Changes
Before Refactoring
Current Architecture (2 Tera templates + per-template infrastructure):
templates/ansible/
├── inventory.yml.tera (Tera: connection details)
└── configure-firewall.yml.tera (Tera: with ssh_port variable)
src/infrastructure/.../ansible/template/
├── wrappers/
│ ├── inventory/
│ │ ├── mod.rs (InventoryTemplate wrapper)
│ │ └── context.rs (InventoryContext)
│ └── firewall_playbook/ (~150 lines)
│ ├── mod.rs (FirewallPlaybookTemplate wrapper)
│ └── context.rs (FirewallPlaybookContext)
└── renderer/
├── inventory.rs (InventoryTemplateRenderer)
└── firewall_playbook.rs (~350 lines - dedicated renderer)
After Refactoring
New Architecture (2 Tera templates + centralized variables):
templates/ansible/
├── inventory.yml.tera (Tera: connection details - UNCHANGED)
├── variables.yml.tera (Tera: NEW - centralized system variables)
└── configure-firewall.yml (Static: uses vars_files)
src/infrastructure/.../ansible/template/
├── wrappers/
│ ├── inventory/
│ │ ├── mod.rs (InventoryTemplate wrapper - UNCHANGED)
│ │ └── context.rs (InventoryContext - UNCHANGED)
│ └── variables/ (NEW ~150 lines)
│ ├── mod.rs (AnsibleVariablesTemplate wrapper)
│ └── context.rs (AnsibleVariablesContext)
└── renderer/
├── inventory.rs (InventoryTemplateRenderer - UNCHANGED)
└── variables.rs (NEW ~200 lines - VariablesTemplateRenderer)
[DELETED: ~500 lines]
- wrappers/firewall_playbook/ directory
- renderer/firewall_playbook.rs file
Key Changes
- Added:
variables.yml.tera template + supporting Rust infrastructure (~350 lines)
- Converted:
configure-firewall.yml.tera → static configure-firewall.yml (no rendering needed)
- Deleted: Firewall playbook renderer and wrapper (~500 lines)
- Net Result: ~150 lines less code, simpler architecture
Acceptance Criteria
Architecture
Functionality
Code Quality
Documentation
Benefits
Architectural Consistency
- Matches OpenTofu's successful
variables.tfvars.tera pattern
- Consistent approach to variable management across infrastructure tools
- Single source of truth for environment-specific values
Reduced Complexity
- Only 1 Tera template instead of multiple
- Less Rust boilerplate for template handling
- Simpler debugging and maintenance
Future-Proofing
- Easy pattern for adding new services (just add variables, write static playbook)
- Scalable approach for the full roadmap implementation
- Clear separation of concerns (variables vs. logic)
Developer Experience
- Easier to understand variable flow
- Centralized variable management
- Reduced cognitive overhead when adding new features
Related Documentation
EPIC: Refactor Ansible Templates to Variables Pattern
Type: EPIC
Parent Epic: #16 - Finish ConfigureCommand - System Security Configuration
Depends On: #18 - Configure UFW Firewall
Overview
This epic tracks the refactoring of Ansible templates to use a centralized variables pattern similar to OpenTofu's
variables.tfvars.teraapproach. This consolidates multiple Tera templates into a single variables file, reducing complexity and establishing a consistent pattern for future Ansible template additions.After implementing the security updates and firewall configuration, we now have 2 Tera templates (
inventory.yml.teraandconfigure-firewall.yml.tera). This refactoring consolidates them into a single variables-based approach that will simplify future service additions.Sub-Tasks
This EPIC uses vertical slice approach - each sub-task is a complete, independently deployable increment:
Goals
variables.yml.terafor all Ansible variablesImplementation Approach
This epic uses vertical slice methodology - each sub-task is a complete, independently deployable increment that includes implementation, cleanup, documentation, and validation. This follows lean/agile principles rather than waterfall phases.
Vertical Slice 1: Create Variables Template Infrastructure (Estimated: 2.5 days)
Complete increment including:
templates/ansible/variables.yml.teratemplate fileAnsibleVariablesContextwith validationAnsibleVariablesTemplatewrapperVariablesTemplateRendererorchestratorAnsibleTemplateRendererworkflowOutcome: System works with new variables infrastructure in place, fully tested and documented.
See: Issue #105
Vertical Slice 2: Convert Firewall to Variables Pattern (Estimated: 4.5 days)
Complete increment including:
configure-firewall.yml.tera→configure-firewall.yml(static)vars_files: [variables.yml]to playbookcopy_static_templates()AnsibleClientto accept extra argumentsOutcome: System works with firewall using variables pattern, old code removed, documentation updated, all tests passing.
See: Issue #106
Total Estimated Time: 7 days (2.5 + 4.5)
Dependencies
High-Level Architecture Changes
Before Refactoring
After Refactoring
Key Changes
variables.yml.teratemplate + supporting Rust infrastructure (~350 lines)configure-firewall.yml.tera→ staticconfigure-firewall.yml(no rendering needed)Acceptance Criteria
Architecture
templates/ansible/variables.yml.teraexists with system configuration variablesconfigure-firewall.ymlis static (no.teraextension) and usesvars_filesinventory.yml.teraremains as Tera template (inventory limitation)firewall_playbookrenderer and wrapper deleted (~500 lines)Functionality
variables.ymlvia-e @variables.ymlCode Quality
cargo test)cargo run --bin e2e-config-tests)cargo run --bin linter all)AnsibleVariablesContext,AnsibleVariablesTemplate, andVariablesTemplateRendererDocumentation
docs/technical/template-system-architecture.mddocuments the variables patterndocs/contributing/templates.mdexplains how to use centralized variablestemplates/ansible/README.mddocuments the variables patternBenefits
Architectural Consistency
variables.tfvars.terapatternReduced Complexity
Future-Proofing
Developer Experience
Related Documentation
docs/issues/19-refactor-ansible-templates-variables-pattern.mddocs/issues/105-create-variables-template.mddocs/issues/106-convert-firewall-template-to-static.md