---
 - name: Add repo file
   template: src=mariadb_ubuntu.list.j2 dest=/etc/apt/sources.list.d/mariadb.list owner=root group=root mode=0644
   register: mariadb_list

 - name: Add repo key (Xenial)
   apt_key:
     keyserver: keyserver.ubuntu.com
     id: "0xF1656F24C74CD1D8"
     state: present
   when: ansible_distribution == 'Ubuntu' and ansible_distribution_release == 'xenial'

 - name: Add repo key (Bionic)
   apt_key:
     keyserver: keyserver.ubuntu.com
     id: "0xF1656F24C74CD1D8"
     state: present
   when: ansible_distribution == 'Ubuntu' and ansible_distribution_release == 'bionic'

 - name: Update apt cache
   apt: update_cache=yes
   when: mariadb_list.changed == True

 - name: Unattended package installation
   shell: export DEBIAN_FRONTEND=noninteractive
   changed_when: false

 - name: Install MariaDB
   apt: pkg="{{ item }}" state=latest
   with_items:
     - mariadb-server
     - mariadb-client

 - name: Start and enable service
   service: name=mysql state=started enabled=yes