--- - name: Install mariadb (Archlinux) become: true pacman: name: - mariadb - python-pymysql when: ansible_distribution == 'Archlinux' - name: Install mariadb (Debian) become: true apt: name: - mariadb - python3-pymysql when: ansible_distribution == 'Debian' - name: Initialize mariadb become: true command: mariadb-install-db --user=mysql --basedir=/usr --datadir=/var/lib/mysql register: result changed_when: "'table already exists!' not in result.stdout" notify: Start mysqld service - name: Secure the installation become: true block: - name: Set root password mysql_user: user=root password="" host=localhost no_log: yes - name: Remove anonymous user for ansible_fqdn mysql_user: user="" host={{ ansible_fqdn }} state=absent - name: Remove anonymous user for localhost mysql_user: user="" state=absent - name: Remove remote root access mysql_user: user=root password="" host={{ item }} no_log: yes with_items: - "::1" - "127.0.0.1" - localhost - name: Remove test database mysql_db: db=test state=absent when: "'table already exists!' not in result.stdout" - name: Stop mysqld service systemd: name: mysqld state: stopped scope: system