Skip to main content

add-new-template

Guide for adding new templates to this project. Covers the Project Generator pattern, the difference between dynamic templates (.tera, automatically discovered) and static templates (must be explicitly registered in copy_static_templates()), and the two-level indirection design (embedded binary → external extraction → build directory rendering). Use when adding infrastructure templates, Ansible playbooks, OpenTofu files, or configuration templates. Triggers on "add template", "new template", "static template", "register template", "copy_static_templates", "project generator", or "template system".

Informações da origem

Repositório
torrust/torrust-tracker-deployer
Última atividade na origem
25 de fevereiro de 2026 às 19:30
Idioma detectado do SKILL.md
inglês
Estrelas
5
Forks
2

Opções de instalação

Por padrão, está selecionado o prompt que primeiro revisa a origem. Você pode mudar para um comando direto ou baixar uma cópia local.

Revise os arquivos de origem

Leia o SKILL.md e os arquivos complementares exibidos pelo SkillsMP antes de decidir se vai instalar.

Exibindo SKILL.md

SKILL.md
Instruções da origem · Visualização somente leitura
name
add-new-template
description
Guide for adding new templates to this project. Covers the Project Generator pattern, the difference between dynamic templates (.tera, automatically discovered) and static templates (must be explicitly registered in copy_static_templates()), and the two-level indirection design (embedded binary → external extraction → build directory rendering). Use when adding infrastructure templates, Ansible playbooks, OpenTofu files, or configuration templates. Triggers on "add template", "new template", "static template", "register template", "copy_static_templates", "project generator", or "template system".
metadata
{"author":"torrust","version":"1.0"}
# Adding New Templates ## Two-Level Template Indirection ```text Embedded in binary → data/templates/ → build/{env}/ (compile time) (extracted once) (rendered per-run) ``` Templates live in `templates/` in the repo. They are compiled into the binary, extracted to `data/templates/` at first use, then rendered into `build/` with variables. ## Template Types | Type | Extension | Processing | Discovery | | ----------- | --------- | -------------------- | ---------------------- | | **Dynamic** | `.tera` | Tera variable subst. | Auto by extension | | **Static** | Any | File copy only | Manual — must register | ## Adding a Dynamic Template (`.tera`) 1. Create the file in `templates/` with a `.tera` extension 2. Use `{{ variable_name }}` syntax for runtime values 3. **No additional registration needed** — automatically discovered ```text templates/ansible/new-config.yml.tera ``` ## Adding a Static Template Static templates (Ansible playbooks, fixed YAML, etc.) require explicit registration. ### Step 1: Create the file ```text templates/ansible/my-new-playbook.yml ``` ### Step 2: Register in copy_static_templates() Find the appropriate `ProjectGenerator` for your template type: ```text src/infrastructure/external_tools/ansible/template/renderer/project_generator.rs ``` Add your file to the `copy_static_templates()` function: ```rust fn copy_static_templates(&self, ...) -> Result<(), Error> { // existing registrations... self.copy_template("ansible/my-new-playbook.yml", ...)?; Ok(()) } ``` **Without this step, the file will never appear in the build directory** and won't be available at runtime. ## Ansible-Specific: Variables Pattern For Ansible playbooks, add runtime variables to `variables.yml.tera`, not the playbook. The playbook loads them via `vars_files: [variables.yml]`. ## Checklist - [ ] File placed in `templates/` directory - [ ] If `.tera`: uses correct `{{ variable }}` syntax - [ ] If static: registered in `copy_static_templates()` in the project generator - [ ] New variables added to `variables.yml.tera` (for Ansible) or equivalent context ## Reference Architecture: [`docs/contributing/templates/template-system-architecture.md`](../../docs/contributing/templates/template-system-architecture.md) Tera syntax: [`docs/contributing/templates/tera.md`](../../docs/contributing/templates/tera.md) Ansible guide: [`docs/contributing/templates/ansible.md`](../../docs/contributing/templates/ansible.md)
Ver no GitHub