Skip to content

Bug: Hardcoded deployment directory in Ansible templates breaks custom deploy_dir #409

@josecelano

Description

@josecelano

Overview

Several Ansible playbook templates under templates/ansible/ hardcode the deployment directory as /opt/torrust instead of using the {{ deploy_dir }} variable sourced from variables.yml. This causes deployment failures when a user configures a custom deployment directory other than the default /opt/torrust.

The correct pattern — used by create-grafana-storage.yml, create-mysql-storage.yml, and deploy-grafana-provisioning.yml — is to load variables.yml via vars_files and reference {{ deploy_dir }} in all paths.

This bug was discovered while deploying the Torrust Tracker demo to the Hetzner provider (#405).

Specification

See detailed specification: docs/issues/409-fix-hardcoded-deploy-dir-in-ansible-templates.md

Implementation Plan

Phase 1: Fix fully hardcoded templates

  • create-tracker-storage.yml: Add vars_files: variables.yml and replace all 3 hardcoded loop items with {{ deploy_dir }}/storage/...
  • create-prometheus-storage.yml: Add vars_files: variables.yml and replace the hardcoded loop item
  • create-backup-storage.yml: Add vars_files: variables.yml and replace 2 hardcoded path: values
  • deploy-backup-config.yml: Add vars_files: variables.yml and replace all 4 hardcoded dest:/path: values
  • deploy-tracker-config.yml: Add vars_files: variables.yml and replace 2 hardcoded dest:/path: values
  • deploy-prometheus-config.yml: Add vars_files: variables.yml and replace 2 hardcoded dest:/path: values
  • init-tracker-database.yml: Add vars_files: variables.yml and replace 2 hardcoded path: values
  • deploy-caddy-config.yml: Add vars_files: variables.yml and replace all 6 hardcoded occurrences

Phase 2: Fix inline-variable templates

  • run-compose-services.yml: Remove inline deploy_dir: /opt/torrust from vars and add vars_files: variables.yml instead
  • deploy-compose-files.yml: Remove inline remote_deploy_dir: /opt/torrust from vars, add vars_files: variables.yml, and rename all remote_deploy_dir references to deploy_dir

Phase 3: Update comments

  • Update inline comments in all modified templates to reference {{ deploy_dir }} instead of /opt/torrust as the example path (where applicable)

Acceptance Criteria

Quality Checks:

  • Pre-commit checks pass: ./scripts/pre-commit.sh

Task-Specific Criteria:

  • No playbook task in templates/ansible/ uses a hardcoded /opt/torrust path in path:, dest:, or loop items
  • All playbooks that reference the deployment directory load variables.yml via vars_files
  • The variable name deploy_dir is used consistently (no remote_deploy_dir or other aliases)
  • Playbooks that previously had inline vars: blocks for the deploy directory no longer define it inline
  • The default behavior (with deploy_dir: /opt/torrust) is unchanged

Related

Metadata

Metadata

Assignees

Labels

ansiblebugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions