--- - name: mysql-conf | Manage the MySQL data directory if not the default one when: mysql_enabled | bool tags: ['mysql', 'mariadb', 'mysql_data_dir'] block: - name: mysql-conf | Check if the new mysql data directory exists ansible.builtin.stat: path: "{{ mysql_data_dir }}" register: my_data_dir - name: mysql-conf | Stop the mysql service while reconfiguring the data directory ansible.builtin.service: name: "{{ mysql_service_name }}" state: stopped when: my_data_dir.stat.isdir is not defined - name: mysql-conf | Create the data directory ansible.builtin.file: dest: "{{ mysql_data_dir }}" state: directory owner: mysql group: mysql mode: "0700" - name: mysql-conf | Copy data to the new directory ansible.posix.synchronize: src: /var/lib/mysql/ dest: "{{ mysql_data_dir }}" delegate_to: "{{ inventory_hostname }}" when: my_data_dir.stat.isdir is not defined - name: mysql-conf | Create the log directory ansible.builtin.file: dest: "{{ mysql_log_dir }}" state: directory owner: mysql group: adm mode: "1750" - name: mysql-conf | Add AppArmor alias ansible.builtin.lineinfile: path: /etc/apparmor.d/tunables/alias line: 'alias /var/lib/mysql/ -> {{ mysql_data_dir }}/,' insertafter: EOF when: my_data_dir.stat.isdir is not defined - name: mysql-conf | Restart the AppArmor service ansible.builtin.service: name: apparmor state: restarted when: my_data_dir.stat.isdir is not defined - name: mysql-conf | Start the mysql service with the new the data directory ansible.builtin.service: name: "{{ mysql_service_name }}" state: started when: my_data_dir.stat.isdir is not defined - name: mysql-conf | Manage the MySQL configuration files when: - mysql_enabled | bool - not mysql_installs_mariadb tags: ['mysql', 'mariadb', 'mysql_conf'] block: - name: mysql-conf | Install the main configuration files. ansible.builtin.template: src: "{{ item }}.cnf.j2" dest: "{{ mysql_conf_dir }}/{{ item }}.cnf" owner: root group: root mode: "0644" loop: - client - mysql-clients notify: Restart mysql - name: mysql-conf | Install the main configuration files. ansible.builtin.template: src: "{{ item }}.cnf.j2" dest: "{{ mysql_service_conf_dir }}/mysqld.cnf" owner: root group: root mode: "0644" with_items: - server notify: Restart mysql - name: mysql-conf | Manage the MariaDB configuration files when: - mysql_enabled | bool - mysql_installs_mariadb tags: ['mysql', 'mariadb', 'mysql_conf'] block: - name: mysql-conf | Configure MariaDB server options community.general.ini_file: section: "{{ item.section }}" option: "{{ item.option }}" value: "{{ item.value }}" state: "{{ item.state }}" dest: "{{ mariadb_server_conf_file }}" backup: false owner: root group: root mode: "0644" loop: "{{ mariadb_server_conf_params }}"