Files
Aditya Hase 30d9e6445c feat(volumes): Set MariaDB to depend on mounts when data volumes are used
If MariaDB gets activated, then mounts will be activated as well.
If one of the mounts fails to activate, MariaDB will not be started.
If one of the mounts is explicitly stopped (or restarted), MariaDB will be stopped (or restarted).

If one of the mounts are stopped, MariaDB will be stopped too.

The mounts strictly have to be in active state for MariaDB to also be in active state.
Reference: https://www.freedesktop.org/software/systemd/man/latest/systemd.unit.html#BindsTo=
2024-11-13 13:30:33 +05:30

140 lines
3.2 KiB
YAML

- name: Add MariaDB Repository Key
apt_key:
url: https://mariadb.org/mariadb_release_signing_key.pgp
state: present
- name: Add MariaDB Repository
apt_repository:
repo: deb https://mirror.rackspace.com/mariadb/repo/10.6/ubuntu {{ ansible_distribution_release }} main
state: present
update_cache: true
- name: Update APT Cache
apt:
update_cache: yes
- name: Use Debian Unattended Package Installation Mode
shell: export DEBIAN_FRONTEND=noninteractive
changed_when: false
- name: Install MariaDB
apt:
pkg:
- mariadb-server
- mariadb-client
- libmariadbclient18
state: present
- name: Install MySQLdb Python Package
apt:
pkg:
- python3-mysqldb
state: present
- name: Add MariaDB Configuration File
template:
src: mariadb.cnf
dest: /etc/mysql/conf.d/frappe.cnf
owner: root
group: root
mode: 0644
- name: Set my.cnf to load frappe.cnf file
lineinfile:
dest: /etc/mysql/my.cnf
line: '!includedir /etc/mysql/conf.d/'
# In Mariadb 10.6, /etc/mysql/mariadb.conf.d/ superseds /etc/mysql/conf.d/. The way to fix it to add !includedir /etc/mysql/conf.d/ to the end of /etc/mysql/my.cnf
# /etc/mysql/conf.d/ is in the second last line of /etc/mysql/my.cnf. Swapping is the way to go.
- name: Remove /etc/mysql/conf.d/ from the file
lineinfile:
path: /etc/mysql/my.cnf
regexp: '^(!includedir /etc/mysql/conf.d/)$'
state: absent
- name: Add /etc/mysql/conf.d/ to the end of the file
lineinfile:
path: /etc/mysql/my.cnf
line: '!includedir /etc/mysql/conf.d/'
- name: Set Open Files Count Limit for MariaDB
lineinfile:
dest: /lib/systemd/system/mariadb.service
regexp: '^LimitNOFILE(\s*)=(\s*)\d+'
line: 'LimitNOFILE = infinity'
insertafter: '\[Service\]'
state: present
- name: Set MariaDB to depend on Mounts
template:
src: mounts.conf
dest: /etc/systemd/system/mariadb.service.d/mounts.conf
owner: root
group: root
mode: 0644
when: mariadb_depends_on_mounts | default(false) | bool
- name: Restart MariaDB Service
systemd:
daemon_reload: true
name: mysql
state: restarted
enabled: yes
- name: Set MariaDB root Password
mysql_user:
login_user: root
login_password: '{{ mariadb_root_password }}'
check_implicit_admin: yes
name: root
host: '{{ item }}'
priv: '*.*:ALL,GRANT'
password: '{{ mariadb_root_password }}'
state: present
with_items:
- localhost
- 127.0.0.1
- ::1
- '%'
- name: Add .my.cnf MariaDB Configuration File
template:
src: my.cnf
dest: /root/.my.cnf
owner: root
group: root
mode: 0600
- name: Remove MariaDB Test Database
mysql_db:
name: test
state: absent
- name: Remove MariaDB Test Users
mysql_user:
name: test
state: absent
- name: Remove Anonymous MariaDB Users
mysql_user:
name: ''
state: absent
- name: Add Frappe User to MySQL Group
user:
name: frappe
groups:
- mysql
append: true
- name: Create Monitor User
mysql_user:
login_user: root
login_password: '{{ mariadb_root_password }}'
check_implicit_admin: yes
name: monitor
host: '%'
priv: 'sys.*:SELECT'
password: 'monitor'
state: present