2023-12-29 22:50:42 +01:00
|
|
|
- name: Create Docker network for MariaDB
|
|
|
|
docker_network:
|
2024-01-05 20:22:34 +01:00
|
|
|
name: central_mariadb
|
2023-12-29 22:50:42 +01:00
|
|
|
state: present
|
2023-12-29 23:48:44 +01:00
|
|
|
when: run_once_docker_mariadb is not defined
|
2023-12-29 22:50:42 +01:00
|
|
|
|
2024-01-03 18:01:58 +01:00
|
|
|
- name: Create a volume for MariaDB socket
|
|
|
|
docker_volume:
|
|
|
|
name: mariadb_socket
|
|
|
|
when: run_once_docker_mariadb is not defined
|
|
|
|
|
2023-12-29 22:50:42 +01:00
|
|
|
- name: install MariaDB
|
|
|
|
docker_container:
|
2024-01-02 21:13:34 +01:00
|
|
|
name: central-mariadb
|
2023-12-31 11:14:18 +01:00
|
|
|
image: mariadb:latest #could lead to problems with nextcloud
|
2023-12-29 22:50:42 +01:00
|
|
|
detach: yes
|
|
|
|
env:
|
2023-12-31 11:14:18 +01:00
|
|
|
MARIADB_ROOT_PASSWORD: "{{central_mariadb_root_password}}"
|
|
|
|
MARIADB_AUTO_UPGRADE: "1"
|
2023-12-29 22:50:42 +01:00
|
|
|
networks:
|
2024-01-05 20:22:34 +01:00
|
|
|
- name: central_mariadb
|
2024-01-02 21:13:34 +01:00
|
|
|
volumes:
|
2024-01-03 18:01:58 +01:00
|
|
|
- central_mariadb_database:/var/lib/mysql
|
2023-12-29 22:50:42 +01:00
|
|
|
published_ports:
|
2024-01-03 18:01:58 +01:00
|
|
|
- "127.0.0.1:3306:3306" # can be that this will be removed if all applications use sockets
|
2023-12-31 11:14:18 +01:00
|
|
|
command: "--transaction-isolation=READ-COMMITTED --binlog-format=ROW" #for nextcloud
|
2024-01-05 22:00:59 +01:00
|
|
|
restart_policy: unless-stopped
|
|
|
|
healthcheck:
|
|
|
|
test: "/usr/bin/mariadb --user=root --password={{central_mariadb_root_password}} --execute \"SHOW DATABASES;\""
|
|
|
|
interval: 3s
|
|
|
|
timeout: 1s
|
|
|
|
retries: 5
|
2023-12-29 23:48:44 +01:00
|
|
|
when: run_once_docker_mariadb is not defined
|
2023-12-29 22:50:42 +01:00
|
|
|
|
2024-01-03 15:46:28 +01:00
|
|
|
- name: install python-mysqlclient
|
|
|
|
pacman:
|
|
|
|
name: python-mysqlclient
|
|
|
|
state: present
|
|
|
|
when: run_once_docker_mariadb is not defined
|
|
|
|
|
2024-01-03 18:01:58 +01:00
|
|
|
- name: wait for database
|
|
|
|
wait_for:
|
|
|
|
host: 127.0.0.1
|
|
|
|
port: 3306
|
|
|
|
delay: 10
|
|
|
|
timeout: 300
|
|
|
|
when: run_once_docker_mariadb is not defined
|
|
|
|
|
2024-01-04 15:07:04 +01:00
|
|
|
- name: "Create database: {{ database_databasename }}"
|
2023-12-31 11:14:18 +01:00
|
|
|
mysql_db:
|
2024-01-03 18:01:58 +01:00
|
|
|
name: "{{ database_databasename }}"
|
2023-12-31 11:14:18 +01:00
|
|
|
state: present
|
|
|
|
login_user: root
|
2024-01-03 18:01:58 +01:00
|
|
|
login_password: "{{ central_mariadb_root_password }}"
|
2023-12-31 11:14:18 +01:00
|
|
|
login_host: 127.0.0.1
|
|
|
|
login_port: 3306
|
|
|
|
|
2024-01-04 15:07:04 +01:00
|
|
|
- name: "Create database user: {{ database_username }}"
|
2023-12-31 11:14:18 +01:00
|
|
|
mysql_user:
|
|
|
|
name: "{{database_username}}"
|
|
|
|
password: "{{database_password}}"
|
2024-01-03 18:01:58 +01:00
|
|
|
host: "%"
|
2023-12-31 11:14:18 +01:00
|
|
|
priv: '{{database_databasename}}.*:ALL'
|
|
|
|
state: present
|
|
|
|
login_user: root
|
|
|
|
login_password: "{{central_mariadb_root_password}}"
|
|
|
|
login_host: 127.0.0.1
|
|
|
|
login_port: 3306
|
|
|
|
|
2023-12-29 22:50:42 +01:00
|
|
|
- name: run the docker_mariadb tasks once
|
|
|
|
set_fact:
|
2023-12-29 23:48:44 +01:00
|
|
|
run_once_docker_mariadb: true
|
|
|
|
when: run_once_docker_mariadb is not defined
|