Renamed Database roles

This commit is contained in:
Kevin Veen-Birkenbach 2025-07-12 10:11:52 +02:00
parent 44834f9873
commit e14e6b96e9
No known key found for this signature in database
GPG Key ID: 44D8F11FD62F878E
46 changed files with 49 additions and 45 deletions

View File

@ -1,18 +1,18 @@
# Database Docker Composition # Database Docker Composition
This role combines the central RDBMS role (`cmp-rdbms-orchestrator`) with Docker Compose to deliver a ready-to-use containerized database environment. This role combines the central RDBMS role (`cmp-rdbms`) with Docker Compose to deliver a ready-to-use containerized database environment.
## Features ## Features
- **Central RDBMS Integration** - **Central RDBMS Integration**
Includes the `cmp-rdbms-orchestrator` role, which handles backups, restores, user and permission management for your relational database system (PostgreSQL, MariaDB, etc.). Includes the `cmp-rdbms` role, which handles backups, restores, user and permission management for your relational database system (PostgreSQL, MariaDB, etc.).
- **Docker Compose** - **Docker Compose**
Utilizes the standalone `docker-compose` role to define and bring up containers, networks, and volumes automatically. Utilizes the standalone `docker-compose` role to define and bring up containers, networks, and volumes automatically.
- **Variable Load Order** - **Variable Load Order**
1. Docker Compose variables (`roles/docker-compose/vars/docker-compose.yml`) 1. Docker Compose variables (`roles/docker-compose/vars/docker-compose.yml`)
2. Database variables (`roles/cmp-rdbms-orchestrator/vars/database.yml`) 2. Database variables (`roles/cmp-rdbms/vars/database.yml`)
Ensures compose ports and volumes are defined before the database role consumes them. Ensures compose ports and volumes are defined before the database role consumes them.
The role will load both sub-roles and satisfy all dependencies transparently. The role will load both sub-roles and satisfy all dependencies transparently.
@ -22,4 +22,4 @@ The role will load both sub-roles and satisfy all dependencies transparently.
1. **Set Fact** `database_application_id` to work around lazyloading ordering. 1. **Set Fact** `database_application_id` to work around lazyloading ordering.
2. **Include Vars** in the specified order. 2. **Include Vars** in the specified order.
3. **Invoke** `docker-compose` role to create containers, networks, and volumes. 3. **Invoke** `docker-compose` role to create containers, networks, and volumes.
4. **Invoke** `cmp-rdbms-orchestrator` role to provision the database, backups, and users. 4. **Invoke** `cmp-rdbms` role to provision the database, backups, and users.

View File

@ -14,4 +14,4 @@
- name: "Load central rdbms for {{ application_id }}" - name: "Load central rdbms for {{ application_id }}"
include_role: include_role:
name: cmp-rdbms-orchestrator name: cmp-rdbms

View File

@ -1,2 +1,2 @@
cmp_db_docker_vars_file_db: "{{ playbook_dir }}/roles/cmp-rdbms-orchestrator/vars/database.yml" cmp_db_docker_vars_file_db: "{{ playbook_dir }}/roles/cmp-rdbms/vars/database.yml"
cmp_db_docker_vars_file_docker: "{{ playbook_dir }}/roles/docker-compose/vars/docker-compose.yml" cmp_db_docker_vars_file_docker: "{{ playbook_dir }}/roles/docker-compose/vars/docker-compose.yml"

View File

@ -1 +0,0 @@
{% include 'roles/cmp-rdbms-orchestrator/templates/services/' + database_type + '.yml.j2' %}

View File

@ -1,5 +1,5 @@
# The following env file will just be used from the dedicated mariadb container # The following env file will just be used from the dedicated mariadb container
# and not the {{applications['rdbms-mariadb'].hostname }}-database # and not the {{applications['mariadb'].hostname }}-database
- name: "Create {{database_env}}" - name: "Create {{database_env}}"
template: template:
src: "env/{{database_type}}.env.j2" src: "env/{{database_type}}.env.j2"
@ -9,8 +9,12 @@
- name: "Create central database" - name: "Create central database"
include_role: include_role:
name: "svc-rdbms-{{database_type}}" name: "svc-{{database_type}}"
when: applications | is_feature_enabled('central_database',application_id) when: applications | is_feature_enabled('central_database',application_id)
#- name: "Create central database"
# include_tasks: "{{ playbook_dir }}/roles/svc-{{database_type}}/tasks/main.yml"
# when: applications | is_feature_enabled('central_database',application_id)
- name: "Add database to backup" - name: "Add database to backup"
include_tasks: "{{ playbook_dir }}/roles/sys-bkp-docker-to-local/tasks/seed-database-to-backup.yml" include_tasks: "{{ playbook_dir }}/roles/sys-bkp-docker-to-local/tasks/seed-database-to-backup.yml"

View File

@ -0,0 +1 @@
{% include 'roles/cmp-rdbms/templates/services/' + database_type + '.yml.j2' %}

View File

@ -1,7 +1,7 @@
# This template needs to be included in docker-compose.yml, which depend on a postgres database # This template needs to be included in docker-compose.yml, which depend on a postgres database
{% if not applications | is_feature_enabled('central_database',application_id) %} {% if not applications | is_feature_enabled('central_database',application_id) %}
{{ database_host }}: {{ database_host }}:
image: postgres:{{applications['rdbms-postgres'].version}}-alpine image: postgres:{{applications['postgres'].version}}-alpine
container_name: {{application_id}}-database container_name: {{application_id}}-database
env_file: env_file:
- {{database_env}} - {{database_env}}

View File

@ -3,7 +3,7 @@ database_host: "{{ 'central-' + database_type if applications | is_feature_
database_name: "{{ applications[database_application_id].database.name | default( database_application_id ) }}" # The overwritte configuration is needed by bigbluebutton database_name: "{{ applications[database_application_id].database.name | default( database_application_id ) }}" # The overwritte configuration is needed by bigbluebutton
database_username: "{{ applications[database_application_id].database.username | default( database_application_id )}}" # The overwritte configuration is needed by bigbluebutton database_username: "{{ applications[database_application_id].database.username | default( database_application_id )}}" # The overwritte configuration is needed by bigbluebutton
database_password: "{{ applications[database_application_id].credentials.database_password }}" database_password: "{{ applications[database_application_id].credentials.database_password }}"
database_port: "{{ 3306 if database_type == 'mariadb' else applications['rdbms-postgres'].port }}" database_port: "{{ 3306 if database_type == 'mariadb' else applications['postgres'].port }}"
database_env: "{{docker_compose.directories.env}}{{database_type}}.env" database_env: "{{docker_compose.directories.env}}{{database_type}}.env"
database_url_jdbc: "jdbc:{{ database_type if database_type == 'mariadb' else 'postgresql' }}://{{ database_host }}:{{ database_port }}/{{ database_name }}" database_url_jdbc: "jdbc:{{ database_type if database_type == 'mariadb' else 'postgresql' }}://{{ database_host }}:{{ database_port }}/{{ database_name }}"
database_url_full: "{{database_type}}://{{database_username}}:{{database_password}}@{{database_host}}:{{database_port}}/{{ database_name }}" database_url_full: "{{database_type}}://{{database_username}}:{{database_password}}@{{database_host}}:{{database_port}}/{{ database_name }}"

View File

@ -2,7 +2,7 @@
services: services:
{# Load Database #} {# Load Database #}
{% if applications[application_id].docker.services.database.enabled | default(false) | bool %} {% if applications[application_id].docker.services.database.enabled | default(false) | bool %}
{% include 'roles/cmp-rdbms-orchestrator/templates/services/main.yml.j2' %} {% include 'roles/cmp-rdbms/templates/services/main.yml.j2' %}
{% endif %} {% endif %}
{# Load Redis #} {# Load Redis #}
{% if applications[application_id].docker.services.redis.enabled | default(false) | bool %} {% if applications[application_id].docker.services.redis.enabled | default(false) | bool %}

View File

@ -0,0 +1,6 @@
# Administration
## Execute SQL commands
```bash
docker exec -it {{applications['mariadb'].hostname }} mariadb -u root -p
```

View File

@ -1,6 +1,6 @@
# defaults/ # defaults/
This directory contains default variable definition files for the `svc-rdbms-mariadb` Ansible role. It centralizes all configurable values related to MariaDB deployment and can be adjusted without modifying task logic. This directory contains default variable definition files for the `svc-mariadb` Ansible role. It centralizes all configurable values related to MariaDB deployment and can be adjusted without modifying task logic.
--- ---
@ -34,7 +34,7 @@ Defines default values for how the MariaDB database should be created.
To customize any of these values without editing role defaults: To customize any of these values without editing role defaults:
1. Create or update a playbook-level vars file (e.g. `group_vars/all/svc-rdbms-mariadb.yml`). 1. Create or update a playbook-level vars file (e.g. `group_vars/all/svc-mariadb.yml`).
2. Set the desired values, for example: 2. Set the desired values, for example:
```yaml ```yaml

View File

@ -8,11 +8,11 @@
- name: install MariaDB - name: install MariaDB
docker_container: docker_container:
name: "{{applications['rdbms-mariadb'].hostname }}" name: "{{applications['mariadb'].hostname }}"
image: "mariadb:{{applications['rdbms-mariadb'].version}}" #could lead to problems with nextcloud image: "mariadb:{{applications['mariadb'].version}}" #could lead to problems with nextcloud
detach: yes detach: yes
env: env:
MARIADB_ROOT_PASSWORD: "{{applications['rdbms-mariadb'].credentials.root_password}}" MARIADB_ROOT_PASSWORD: "{{applications['mariadb'].credentials.root_password}}"
MARIADB_AUTO_UPGRADE: "1" MARIADB_AUTO_UPGRADE: "1"
networks: networks:
- name: central_mariadb - name: central_mariadb
@ -23,7 +23,7 @@
command: "--transaction-isolation=READ-COMMITTED --binlog-format=ROW" #for nextcloud command: "--transaction-isolation=READ-COMMITTED --binlog-format=ROW" #for nextcloud
restart_policy: "{{docker_restart_policy}}" restart_policy: "{{docker_restart_policy}}"
healthcheck: healthcheck:
test: "/usr/bin/mariadb --user=root --password={{applications['rdbms-mariadb'].credentials.root_password}} --execute \"SHOW DATABASES;\"" test: "/usr/bin/mariadb --user=root --password={{applications['mariadb'].credentials.root_password}} --execute \"SHOW DATABASES;\""
interval: 3s interval: 3s
timeout: 1s timeout: 1s
retries: 5 retries: 5
@ -38,7 +38,7 @@
- name: Wait until the MariaDB container is healthy - name: Wait until the MariaDB container is healthy
community.docker.docker_container_info: community.docker.docker_container_info:
name: "{{ applications['rdbms-mariadb'].hostname }}" name: "{{ applications['mariadb'].hostname }}"
register: db_info register: db_info
until: until:
- db_info.containers is defined - db_info.containers is defined
@ -56,7 +56,7 @@
name: "{{ database_name }}" name: "{{ database_name }}"
state: present state: present
login_user: root login_user: root
login_password: "{{ applications['rdbms-mariadb'].credentials.root_password }}" login_password: "{{ applications['mariadb'].credentials.root_password }}"
login_host: 127.0.0.1 login_host: 127.0.0.1
login_port: "{{ database_port }}" login_port: "{{ database_port }}"
encoding: "{{ database_encoding }}" encoding: "{{ database_encoding }}"
@ -70,7 +70,7 @@
priv: '{{database_name}}.*:ALL' priv: '{{database_name}}.*:ALL'
state: present state: present
login_user: root login_user: root
login_password: "{{applications['rdbms-mariadb'].credentials.root_password}}" login_password: "{{applications['mariadb'].credentials.root_password}}"
login_host: 127.0.0.1 login_host: 127.0.0.1
login_port: "{{database_port}}" login_port: "{{database_port}}"
@ -78,7 +78,7 @@
# @todo Remove if this works fine in the future. # @todo Remove if this works fine in the future.
#- name: Grant database privileges #- name: Grant database privileges
# ansible.builtin.shell: # ansible.builtin.shell:
# cmd: "docker exec {{applications['rdbms-mariadb'].hostname }} mariadb -u root -p{{ applications['rdbms-mariadb'].credentials.root_password }} -e \"GRANT ALL PRIVILEGES ON `{{database_name}}`.* TO '{{database_username}}'@'%';\"" # cmd: "docker exec {{applications['mariadb'].hostname }} mariadb -u root -p{{ applications['mariadb'].credentials.root_password }} -e \"GRANT ALL PRIVILEGES ON `{{database_name}}`.* TO '{{database_username}}'@'%';\""
# args: # args:
# executable: /bin/bash # executable: /bin/bash

View File

@ -1,6 +1,6 @@
# vars/ # vars/
This directory contains variable definition files for the `svc-rdbms-mariadb` Ansible role. It centralizes all configurable values related to MariaDB deployment and can be adjusted without modifying task logic. This directory contains variable definition files for the `svc-mariadb` Ansible role. It centralizes all configurable values related to MariaDB deployment and can be adjusted without modifying task logic.
--- ---

View File

@ -0,0 +1 @@
application_id: mariadb

View File

@ -3,5 +3,5 @@
## Root Access ## Root Access
To access the database via the root account execute the following on the server: To access the database via the root account execute the following on the server:
```bash ```bash
docker exec -it "{{ applications['rdbms-postgres'].hostname }}" psql -U postgres docker exec -it "{{ applications['postgres'].hostname }}" psql -U postgres
``` ```

View File

@ -0,0 +1 @@
application_id: postgres

View File

@ -1,6 +0,0 @@
# Administration
## Execute SQL commands
```bash
docker exec -it {{applications['rdbms-mariadb'].hostname }} mariadb -u root -p
```

View File

@ -1 +0,0 @@
application_id: rdbms-mariadb

View File

@ -1 +0,0 @@
application_id: rdbms-postgres

View File

@ -133,7 +133,7 @@ def update_discourse(directory):
update_procedure("docker stop {{applications.discourse.container}}") update_procedure("docker stop {{applications.discourse.container}}")
update_procedure("docker rm {{applications.discourse.container}}") update_procedure("docker rm {{applications.discourse.container}}")
try: try:
update_procedure("docker network connect {{applications.discourse.network}} {{ applications['rdbms-postgres'].hostname }}") update_procedure("docker network connect {{applications.discourse.network}} {{ applications['postgres'].hostname }}")
except subprocess.CalledProcessError as e: except subprocess.CalledProcessError as e:
error_message = e.output.decode() error_message = e.output.decode()
if "already exists" in error_message or "is already connected" in error_message: if "already exists" in error_message or "is already connected" in error_message:

View File

@ -43,13 +43,13 @@
meta: flush_handlers meta: flush_handlers
when: run_once_docker_discourse is not defined when: run_once_docker_discourse is not defined
- name: "Connect {{ applications[application_id].container }} to network {{ applications['rdbms-postgres'].network }}" - name: "Connect {{ applications[application_id].container }} to network {{ applications['postgres'].network }}"
command: > command: >
docker network connect {{ applications['rdbms-postgres'].network }} {{ applications[application_id].container }} docker network connect {{ applications['postgres'].network }} {{ applications[application_id].container }}
register: network_connect register: network_connect
failed_when: > failed_when: >
network_connect.rc != 0 and network_connect.rc != 0 and
'Error response from daemon: endpoint with name {{ applications[application_id].container }} already exists in network {{ applications['rdbms-postgres'].network }}' 'Error response from daemon: endpoint with name {{ applications[application_id].container }} already exists in network {{ applications['postgres'].network }}'
not in network_connect.stderr not in network_connect.stderr
changed_when: network_connect.rc == 0 changed_when: network_connect.rc == 0
when: when:

View File

@ -1,5 +1,5 @@
- name: "Load database variables for reset function" - name: "Load database variables for reset function"
include_vars: "{{playbook_dir}}/roles/cmp-rdbms-orchestrator/vars/main.yml" include_vars: "{{playbook_dir}}/roles/cmp-rdbms/vars/main.yml"
- name: "cleanup central database from {{application_id}}_default network" - name: "cleanup central database from {{application_id}}_default network"
command: command:

View File

@ -8,7 +8,7 @@ Enhance your sales and service processes with EspoCRM, an open-source CRM featur
This Ansible role deploys EspoCRM using Docker. It handles: This Ansible role deploys EspoCRM using Docker. It handles:
- MariaDB database provisioning via the `cmp-rdbms-orchestrator` role - MariaDB database provisioning via the `cmp-rdbms` role
- Nginx domain setup with WebSocket and reverse-proxy configuration - Nginx domain setup with WebSocket and reverse-proxy configuration
- Environment variable management through Jinja2 templates - Environment variable management through Jinja2 templates
- Docker Compose orchestration for **web**, **daemon**, and **websocket** services - Docker Compose orchestration for **web**, **daemon**, and **websocket** services

View File

@ -14,7 +14,7 @@ The following environment variables need to be defined for successful operation:
To completely reset Friendica, including its database and volumes, run: To completely reset Friendica, including its database and volumes, run:
```bash ```bash
docker exec -i {{applications['rdbms-mariadb'].hostname }} mariadb -u root -p"${DB_ROOT_PASSWORD}" -e "DROP DATABASE IF EXISTS friendica; CREATE DATABASE friendica;" docker exec -i {{applications['mariadb'].hostname }} mariadb -u root -p"${DB_ROOT_PASSWORD}" -e "DROP DATABASE IF EXISTS friendica; CREATE DATABASE friendica;"
docker compose down docker compose down
rm -rv /mnt/hdd/data/docker/volumes/friendica_data rm -rv /mnt/hdd/data/docker/volumes/friendica_data
docker volume rm friendica_data docker volume rm friendica_data
@ -25,7 +25,7 @@ docker volume rm friendica_data
## Manual Method: ## Manual Method:
1. Connect to the MariaDB instance: 1. Connect to the MariaDB instance:
```bash ```bash
docker exec -it {{applications['rdbms-mariadb'].hostname }} mariadb -u root -p docker exec -it {{applications['mariadb'].hostname }} mariadb -u root -p
``` ```
2. Run the following commands: 2. Run the following commands:
```sql ```sql
@ -37,7 +37,7 @@ docker volume rm friendica_data
## Automatic Method: ## Automatic Method:
```bash ```bash
DB_ROOT_PASSWORD="your_root_password" DB_ROOT_PASSWORD="your_root_password"
docker exec -i {{applications['rdbms-mariadb'].hostname }} mariadb -u root -p"${DB_ROOT_PASSWORD}" -e "DROP DATABASE IF EXISTS friendica; CREATE DATABASE friendica;" docker exec -i {{applications['mariadb'].hostname }} mariadb -u root -p"${DB_ROOT_PASSWORD}" -e "DROP DATABASE IF EXISTS friendica; CREATE DATABASE friendica;"
``` ```
## Enter the Application Container 🔍 ## Enter the Application Container 🔍

View File

@ -6,7 +6,7 @@
# - database_password # - database_password
- name: "create {{database_name}} database" - name: "create {{database_name}} database"
include_role: include_role:
name: svc-rdbms-postgres name: svc-postgres
when: applications | is_feature_enabled('central_database',application_id) when: applications | is_feature_enabled('central_database',application_id)
- name: "include seed-database-to-backup.yml" - name: "include seed-database-to-backup.yml"

View File

@ -9,6 +9,6 @@ pgadmin_servers:
port: "{{ database_port }}" port: "{{ database_port }}"
username: "postgres" username: "postgres"
maintenance_db: "postgres" maintenance_db: "postgres"
password: "{{ applications['rdbms-postgres'].credentials.postgres_password }}" password: "{{ applications['postgres'].credentials.postgres_password }}"
# Here you can add more databases # Here you can add more databases

View File

@ -1,7 +1,7 @@
# Configuration @see https://hub.docker.com/_/phpmyadmin # Configuration @see https://hub.docker.com/_/phpmyadmin
PMA_HOST={{applications['rdbms-mariadb'].hostname}} PMA_HOST={{applications['mariadb'].hostname}}
{% if applications[application_id].autologin | bool %} {% if applications[application_id].autologin | bool %}
PMA_USER= root PMA_USER= root
PMA_PASSWORD= "{{applications['rdbms-mariadb'].credentials.root_password}}" PMA_PASSWORD= "{{applications['mariadb'].credentials.root_password}}"
{% endif %} {% endif %}