--- - name: Install MariaDB apt: name: - mariadb-client - mariadb-server - python3-mysqldb state: present - name: Enable MariaDB service on boot (workaround for systemctl broken handling of SysV) command: rcconf -on mysql register: result changed_when: not result.stderr - name: Enable and start MariaDB service: name: mysql state: started - name: Set password for the root database user mysql_user: check_implicit_admin: true name: root password: "{{ db_root_password }}" - name: Deploy username and password for the root database user template: src: "root_my.cnf.j2" dest: "/root/.my.cnf" owner: root group: root mode: 0400 - name: Check if root user authentication is based on use of unix_socket module command: mysql --skip-column-names -B -e "select 1 from mysql.user where user='root' and plugin='unix_socket';" register: "root_using_unix_socket_authentication" changed_when: false # @TODO: This is essentially a leftover from the days of Debian # Jessie, which by default did not use unix socket # authentication for the root account. To make the deployment # the same on both distros, unix socket authentication was # disabled on Debian Stretch at the time. It might be worth the # effort to revisit this and figure out if unix socket # authentication should be reenabled instead (and whether # password for the root account should be used at all). - name: Disable use of unix socket login command: "mysql -B -e \"update mysql.user set plugin='' where user='root' and plugin='unix_socket'; flush privileges;\"" when: "root_using_unix_socket_authentication.stdout" - name: Set UTF-8 encoding as default for MariaDB copy: src: "utf8.cnf" dest: "/etc/mysql/mariadb.conf.d/90-utf8.cnf" owner: root group: root mode: 0644 register: mariadb_utf8_configuration - name: Restart MariaDB in order to use UTF-8 as default character set service: name: mysql state: restarted when: mariadb_utf8_configuration.changed tags: # [ANSIBLE0016] Tasks that run when changed should likely be handlers # UTF-8 configuration must be applied immediatelly in order to ensure that # subsequent tasks that create databases will end-up with correct (UTF-8) # encoding. Otherwise they will be created using default latin1. - skip_ansible_lint - name: Explicitly run all handlers include: ../handlers/main.yml when: "run_handlers | default(False) | bool()" tags: - handlers