fix(postgres): pin provider context on 02_init for nested/looped consumers

svc-db-postgres 02_init.yml asserts application_id == 'svc-db-postgres' AND database_consumer_id \!= 'svc-db-postgres'. When 01_core is skipped (run-once), the include_role application_id var does not reliably reach 02_init through a consumer's nested looped include (web-app-matrix's per-bridge DB seeding), so the assert fails. Pin application_id on the 02_init include so it holds for any caller. On the matrix side, freeze the consumer id eagerly before the provider include so database_consumer_id stays the matrix consumer instead of lazily resolving to svc-db-postgres once application_id is pinned.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
kevinveenbirkenbachandClaude Opus 4.8 committed 2026-06-23 11:17:59 +02:00
1 parent bf32cab5ef
commit 0bbd6c43ff
2 files changed
+17 -7

No files matched your search

+2
View File
@@ -12,3 +12,5 @@
- name: "Initialize dedicated database"
include_tasks: 02_init.yml
when: database_init | bool
vars:
application_id: svc-db-postgres
@@ -4,21 +4,29 @@
# - database_username
# - database_password
- name: "Freeze database consumer id + provider role before provider include"
ansible.builtin.set_fact:
_matrix_db_consumer_id: "{{ application_id }}"
_matrix_db_provider_role: "{{ lookup('database', application_id, 'id') }}"
changed_when: false
- name: "Create DB/user for '{{ database_name }}' in central DB"
include_role:
name: "{{ lookup('database', application_id, 'id') }}"
name: "{{ _matrix_db_provider_role }}"
public: false
vars:
database_init: true
database_consumer_id: "{{ application_id }}"
database_type: "{{ lookup('database', application_id, 'type') }}"
when: lookup('database', application_id, 'shared') | bool
compose_repository_pull: false
database_consumer_id: "{{ _matrix_db_consumer_id }}"
database_type: "{{ lookup('database', _matrix_db_consumer_id, 'type') }}"
when: lookup('database', _matrix_db_consumer_id, 'shared') | bool
- name: "Seed database entry to backup routine"
include_tasks: "{{ playbook_dir }}/roles/svc-bkp-container-2-local/tasks/04_seed-database-to-backup.yml"
vars:
database_consumer_id: "{{ application_id }}"
database_type: "{{ lookup('database', application_id, 'type') }}"
database_instance: "{{ lookup('database', application_id, 'instance') }}"
database_consumer_id: "{{ _matrix_db_consumer_id }}"
database_type: "{{ lookup('database', _matrix_db_consumer_id, 'type') }}"
database_instance: "{{ lookup('database', _matrix_db_consumer_id, 'instance') }}"
database_host: "{{ MATRIX_POSTGRES_HOST }}"
database_port: "{{ MATRIX_POSTGRES_PORT }}"
database_name: "{{ database_name }}"