--- # ============================================================================= # Upgrade Tasks - Deploy New docker-compose.yml # ============================================================================= # # Deploys the templated docker-compose.yml with the new Gitea version. # # This task uses Ansible's template module to generate docker-compose.yml # from a Jinja2 template. The template allows us to: # - Update the Gitea image version # - Update the PostgreSQL image version # - Apply configuration from Ansible variables # # The template is stored at: roles/gitea/templates/docker-compose.yml.j2 # # After this task, the docker-compose.yml on the server will reference # the new image versions, but containers aren't restarted yet. # That happens in deploy.yml. # ============================================================================= # ----------------------------------------------------------------------------- # Backup Current docker-compose.yml # ----------------------------------------------------------------------------- # Even though we have a full gitea dump backup, it's useful to have # the docker-compose.yml readily available for quick rollback. - name: Backup current docker-compose.yml before upgrade ansible.builtin.copy: src: "{{ gitea_install_dir }}/docker-compose.yml" dest: "{{ gitea_install_dir }}/docker-compose.yml.backup" remote_src: true mode: "0640" # ----------------------------------------------------------------------------- # Deploy New docker-compose.yml from Template # ----------------------------------------------------------------------------- # The template module: # 1. Reads the Jinja2 template (docker-compose.yml.j2) # 2. Substitutes all {{ variable }} placeholders with actual values # 3. Writes the result to the destination path # # Key variables used in the template: # gitea_version - Docker image tag (e.g., "1.25") # postgres_version - PostgreSQL image tag (e.g., "17-alpine") # gitea_db_password - Database password (from vault) # gitea_user_uid/gid - Container user/group IDs # gitea_http_port - Internal HTTP port (3000) # gitea_ssh_port - Internal SSH port (22) # gitea_ssh_external_port - External SSH port (2222) - name: Deploy docker-compose.yml from template ansible.builtin.template: src: docker-compose.yml.j2 dest: "{{ gitea_install_dir }}/docker-compose.yml" mode: "0640" # Validate the YAML syntax before deploying validate: "docker compose -f %s config --quiet" register: gitea_compose_deployed # Display what changed for operator visibility - name: Display upgrade info ansible.builtin.debug: msg: | docker-compose.yml updated: Gitea version: {{ gitea_version }} PostgreSQL version: {{ gitea_postgres_version }} Template changed: {{ gitea_compose_deployed.changed }}