From b1410f91a0921efb293aa2a2e39d7f072e7d61ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xavi=20Lle=C3=B3=20Tom=C3=A1s?= Date: Wed, 11 Dec 2024 12:04:37 +0100 Subject: [PATCH] Refs #8140: MariaDB Server Deploy - Role WIP --- roles/services/tasks/mariadb.yml | 101 +++++++++++-------------------- 1 file changed, 36 insertions(+), 65 deletions(-) diff --git a/roles/services/tasks/mariadb.yml b/roles/services/tasks/mariadb.yml index 9ee1c88..295afb7 100644 --- a/roles/services/tasks/mariadb.yml +++ b/roles/services/tasks/mariadb.yml @@ -4,29 +4,20 @@ state: present #install_recommends: no -- name: Ensure log directory exists /var/log/mysql +- name: Ensure required directories exist file: - path: /var/log/mysql + path: "{{ item.path }}" state: directory - owner: mysql - group: adm - mode: u=rwx,g=rxs,o= - -- name: Ensure mysqlbin directory exists /mnt/mysqlbin - file: - path: /mnt/mysqlbin - state: directory - owner: root - group: root - mode: u=rwx,g=rx,o=rx - -- name: Ensure mysqltmp directory exists /mnt/mysqltmp with sticky bit - file: - path: /mnt/mysqltmp - state: directory - mode: u=rwx,g=rwx,o=rwxt - owner: root - group: root + owner: "{{ item.owner }}" + group: "{{ item.group }}" + mode: "{{ item.mode }}" + loop: + - { path: /var/log/mysql, owner: mysql, group: adm, mode: 'u=rwx,g=rxs,o=' } + - { path: /root/scripts, owner: root, group: root, mode: 'u=rwx,g=rx,o=rx' } + - { path: /mnt/mysqlbin, owner: root, group: root, mode: 'u=rwx,g=rx,o=rx' } + - { path: /etc/systemd/system/mariadb.service.d, owner: root, group: root, mode: 'u=rwx,g=rx,o=rx' } + - { path: /mnt/mysqltmp, owner: root, group: root, mode: 'u=rwx,g=rwx,o=rwxt' } + - { path: /mnt/mysqlbin/binlog, owner: mysql, group: mysql, mode: 'u=rwx,g=,o=' } - name: Set MariaDB custom configuration copy: @@ -39,31 +30,6 @@ - "files/z9*.cnf" notify: restart-mariadb -- name: Ensure mariadb service override directory exists - file: - path: /etc/systemd/system/mariadb.service.d - state: directory - owner: root - group: root - mode: u=rwx,g=rx,o=rx - -- name: Set MariaDB custom service.d override.conf - copy: - src: mariadb_override.conf - dest: /etc/systemd/system/mariadb.service.d/override.conf - owner: root - group: root - mode: u=rw,g=r,o=r - notify: reload systemd - -- name: Ensure scripts root directory exists - file: - path: /root/scripts - state: directory - owner: root - group: root - mode: u=rwx,g=rx,o=rx - - name: Set MariaDB custom root scripts copy: src: "{{ item }}" @@ -74,26 +40,31 @@ with_fileglob: - "files/scripts/*.sh" -- name: Set MariaDB README root script - copy: - src: files/scripts/README.md - dest: /root/scripts/README.md +- name: Ensure required files are copied to their destinations + ansible.builtin.copy: + src: "{{ item.src }}" + dest: "{{ item.dest }}" owner: root group: root - mode: u=rw,g=r,o=r + mode: "{{ item.mode }}" + loop: + - { src: 'files/scripts/README.md', dest: '/root/scripts/README.md', mode: 'u=rw,g=r,o=r' } + - { src: 'mariadb_override.conf', dest: '/etc/systemd/system/mariadb.service.d/override.conf', mode: 'u=rw,g=r,o=r' } + - { src: 'files/scripts/mysqltuner.pl', dest: '/root/scripts/mysqltuner.pl', mode: 'u=rwx,g=rx,o=rx' } + notify: + - reload systemd -- name: Set MariaDB performance and customize root script - copy: - src: files/scripts/mysqltuner.pl - dest: /root/scripts/mysqltuner.pl - owner: root - group: root - mode: u=rwx,g=rx,o=rx +#- name: Set MariaDB Cron to /etc/cron.d +# template: +# src: templates/cron_mariadb +# dest: /etc/cron.d/vn +# owner: root +# group: root +# mode: u=rw,g=r,o=r -- name: Set MariaDB Cron to /etc/cron.d - template: - src: templates/cron_mariadb - dest: /etc/cron.d/vn - owner: root - group: root - mode: u=rw,g=r,o=r +- name: Add tmpfs in /etc/fstab + blockinfile: + path: /etc/fstab + marker: "# {mark} ANSIBLE-MANAGED TMPFS ENTRY" + block: | + tmpfs /mnt/mysqltmp tmpfs rw,size=6144M 0 0