--- - name: INCLUDE_VARS | Extra variables ansible.builtin.include_vars: "{{ lookup('first_found', params) }}" vars: params: files: - '{{ ansible_distribution }}-{{ ansible_distribution_release }}.yml' - default.yml paths: - 'vars' - name: STAT | Check if mysql exists ansible.builtin.stat: path: /usr/sbin/mysqld register: mariadb_exists changed_when: false - name: INCLUDE | Install ansible.builtin.import_tasks: install/main.yml - name: SHELL | Get current mariadb version # noqa: risky-shell-pipe ansible.builtin.shell: dpkg -l mariadb-common | awk '/^ii/ { print $3 }' | sed -r 's/^1://g; s/^([[:digit:]]+\.[[:digit:]]+).+$/\1/g' register: __mariadb_version changed_when: false - name: TEMPLATE | Deploy config files ansible.builtin.template: src: "{{ item }}" dest: "/{{ item | replace('.j2', '') }}" mode: 0644 owner: root group: root register: config loop: - etc/mysql/conf.d/mysqldump.cnf.j2 - etc/mysql/mariadb.conf.d/10-extra.cnf.j2 - etc/mysql/mariadb.conf.d/50-server.cnf.j2 notify: Restart mariadb - name: FILE | Ensure log dir exists ansible.builtin.file: path: "{{ mariadb_slow_query_log_file | dirname }}" state: directory mode: 0755 owner: mysql group: mysql - name: META | Flush handlers ansible.builtin.meta: flush_handlers - name: SERVICE | Ensure service is started ansible.builtin.service: name: "{{ mariadb_service_name }}" state: started - name: INCLUDE | Galera ansible.builtin.import_tasks: galera/main.yml when: mariadb_use_galera - name: INCLUDE | Replication ansible.builtin.import_tasks: replication/main.yml when: mariadb_replication_master or mariadb_replication_slave - name: INCLUDE | Secure install ansible.builtin.import_tasks: 'secure.yml' - name: MYSQL_DB | Create databases community.mysql.mysql_db: name: "{{ item }}" state: present login_unix_socket: "{{ mariadb_socket }}" loop: "{{ mariadb_databases }}" - name: MYSQL_USER | Manages users... community.mysql.mysql_user: name: "{{ item.name }}" password: "{{ item.password }}" priv: "{{ item.priv }}" host: "{{ item.host | default(omit) }}" host_all: "{{ item.host_all | default(omit) }}" state: present login_unix_socket: "{{ mariadb_socket }}" loop: "{{ mariadb_users }}" no_log: "{{ not mariadb_debug_role }}"