--- - name: Install mariadb (Archlinux) become: true pacman: name: - mariadb when: ansible_distribution == 'Archlinux' - name: Install mariadb (Debian) become: true apt: name: - mariadb 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 # TODO: This won't work because it is interactive. # https://stackoverflow.com/questions/25136498/ansible-answers-to-mysql-secure-installation#25140114 become: true command: mysql_secure_installation when: "'table already exists!' not in result.stdout" - name: Stop mysqld service systemd: name: mysqld state: stopped scope: system