Refactor DB initialization handling: externalize database_init flag for svc-db-mariadb and svc-db-postgres, remove internal auto-detection, and pass explicit init signal from sys-stk-back-stateful. Improves clarity, avoids incorrect credential lookups, and stabilizes central DB setup.

Reference: ChatGPT conversation https://chatgpt.com/share/692def1c-a79c-800f-b7dd-35e1845424bf
This commit is contained in:
2025-12-01 20:40:30 +01:00
parent 116c20d61d
commit 8314d7e6a6
8 changed files with 19 additions and 17 deletions

View File

@@ -1,3 +1,4 @@
# Check out the README.md file for more information, why this encodings and collations are used
database_encoding: "utf8mb4"
database_collation: "utf8mb4_unicode_ci"
database_collation: "utf8mb4_unicode_ci"
database_init: false # When true a database is initialized

View File

@@ -1,7 +1,7 @@
- name: Create Docker network for MariaDB
community.docker.docker_network:
name: "{{ mariadb_network_name }}"
name: "{{ mariadb_network }}"
state: present
ipam_config:
- subnet: "{{ mariadb_subnet }}"
@@ -15,7 +15,7 @@
MARIADB_ROOT_PASSWORD: "{{ mariadb_root_pwd }}"
MARIADB_AUTO_UPGRADE: "1"
networks:
- name: "{{ mariadb_network_name }}"
- name: "{{ mariadb_network }}"
volumes:
- "{{ mariadb_volume }}:/var/lib/mysql"
published_ports:

View File

@@ -3,4 +3,4 @@
- name: "Initialize database for '{{ database_name }}'"
include_tasks: 02_init.yml
when: "{{ mariadb_init }}"
when: database_init | bool

View File

@@ -1,10 +1,9 @@
application_id: svc-db-mariadb
mariadb_root_pwd: "{{ applications | get_app_conf(application_id,'credentials.root_password', True) }}"
mariadb_init: "{{ database_username is defined and database_password is defined and database_name is defined }}"
mariadb_subnet: "{{ networks.local['svc-db-mariadb'].subnet }}"
mariadb_network_name: "{{ applications | get_app_conf(application_id,'docker.network', True) }}"
mariadb_volume: "{{ applications | get_app_conf(application_id,'docker.volumes.data', True) }}"
mariadb_image: "{{ applications | get_app_conf(application_id,'docker.services.mariadb.image','mariadb', True) }}"
mariadb_version: "{{ applications | get_app_conf(application_id,'docker.services.mariadb.version', True) }}"
mariadb_name: "{{ applications | get_app_conf(application_id,'docker.services.mariadb.name', True) }}"
mariadb_port: "{{ database_port | default(ports.localhost.database[ application_id ]) }}"
application_id: svc-db-mariadb
mariadb_root_pwd: "{{ applications | get_app_conf(application_id,'credentials.root_password') }}"
mariadb_subnet: "{{ networks.local['svc-db-mariadb'].subnet }}"
mariadb_network: "{{ applications | get_app_conf(application_id,'docker.network') }}"
mariadb_volume: "{{ applications | get_app_conf(application_id,'docker.volumes.data') }}"
mariadb_image: "{{ applications | get_app_conf(application_id,'docker.services.mariadb.image','mariadb') }}"
mariadb_version: "{{ applications | get_app_conf(application_id,'docker.services.mariadb.version') }}"
mariadb_name: "{{ applications | get_app_conf(application_id,'docker.services.mariadb.name') }}"
mariadb_port: "{{ database_port | default(ports.localhost.database[ application_id ]) }}"

View File

@@ -1 +1,2 @@
postgres_gis_enabled: false # Needed by mobilizon
postgres_gis_enabled: false # Needed by mobilizon
database_init: false # When true a database is initialized

View File

@@ -11,4 +11,4 @@
- name: "Initialize database for '{{ database_name }}'"
include_tasks: 02_init.yml
when: POSTGRES_INIT | bool
when: database_init | bool

View File

@@ -18,7 +18,6 @@ POSTGRES_NETWORK_NAME: "{{ applications | get_app_conf(applic
POSTGRES_SUBNET: "{{ networks.local['svc-db-postgres'].subnet }}"
POSTGRES_PASSWORD: "{{ applications | get_app_conf(application_id, 'credentials.POSTGRES_PASSWORD') }}"
POSTGRES_PORT: "{{ database_port | default(ports.localhost.database[ application_id ]) }}"
POSTGRES_INIT: "{{ database_username is defined and database_password is defined and database_name is defined }}"
POSTGRES_EXPOSE_LOCAL: True # Exposes the db to localhost, almost everytime neccessary
POSTGRES_CUSTOM_IMAGE_NAME: "postgres_custom"
POSTGRES_LOCAL_HOST: "127.0.0.1"

View File

@@ -13,6 +13,8 @@
- name: "For '{{ application_id }}': Load central RDBMS"
include_role:
name: sys-svc-rdbms
vars:
database_init: true # Initialize a custom database for the application
- name: "For '{{ application_id }}': Load sys-stk-back-stateless"
include_role: