--- - name: Install mariadb become: true apt: name: - mariadb-server - python3-pymysql state: present update_cache: yes - 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 mariadb service - name: Secure the installation become: true block: - name: Set root password mysql_user: user=root password="" host=localhost - 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 }} with_items: - "::1" - "127.0.0.1" - localhost - name: Remove test database mysql_db: db=test state=absent