--- - name: Create the data directory ansible.builtin.file: path: '{{ mariadb_full_config.mysqld.datadir }}' owner: '{{ mariadb_full_config.mysqld.user }}' group: root mode: 0750 state: directory tags: mariadb - name: Initialize database # noqa no-changed-when ansible.builtin.command: args: argv: - mysql_install_db - '--datadir={{ mariadb_full_config.mysqld.datadir }}' - '--user={{ mariadb_full_config.mysqld.user }}' - '--skip-name-resolve' - '--no-defaults' tags: mariadb - name: Start mariadb ansible.builtin.service: name: mysql state: started tags: mariadb - name: Wait mysql start ansible.builtin.pause: seconds: 5 tags: mariadb - name: Set root password # noqa no-changed-when ansible.builtin.command: 'mysqladmin -u root password {{ mariadb_password }}' tags: mariadb - name: Remove anonymous users community.mysql.mysql_user: name: '' host_all: yes state: absent login_user: '{{ mariadb_user }}' login_password: '{{ mariadb_password }}' tags: mariadb - name: Remove root user without password community.mysql.mysql_user: name: root host: '{{ item }}' state: absent login_user: '{{ mariadb_user }}' login_password: '{{ mariadb_password }}' loop: - 127.0.0.1 - '::1' - '{{ ansible_nodename }}' tags: mariadb