- hosts: localhost tasks: - name: "mysql/service : Test if directory exists" stat: path: /var/lib/mysql/mysql register: MYSQL_DIRECTORY_RESULT ignore_errors: true - name: "mysql/service : Setup mariadb" shell: | /etc/init.d/mariadb setup when: not MYSQL_DIRECTORY_RESULT.stat.exists - name: Enable mariadb service service: name: mariadb state: started enabled: true