- hosts: localhost tasks: - name: Install mariadb package package: state: present name: - mariadb - mariadb-client - mariadb-openrc - py3-mysqlclient - name: Update MariaDB root password mysql_user: name=root host={{item}} password={{mysql_root_password}} with_items: - 127.0.0.1 - ::1 - localhost - name: Set ~/.my.cnf file template: - src: files/mysql_secure-installation-my.conf.j2 - dest: /root/.my.cnf - mode: '0600' vars: MYSQL_ROOT_PASSWORD: "{{mysql_root_password}}" - name: Delete anonymous MySQL user mysql_user: name="" host={{item}} state=absent with_items: - localhost - "{{ansible_nodename}}" - name: Delete Hostname based MySQL user mysql_user: name=root host="{{ansible_nodename}}" state=absent - name: Remove MySQL test database mysql_db: name: test state: absent