---
- name: Update MariaDB Dependencies
  shell: >-
    curl -sSL https://downloads.mariadb.com/MariaDB/mariadb_repo_setup
    | bash -s -- --mariadb-server-version="mariadb-10.5"

- name: Remove old MariaDB conf files
  file:
    path: "{{ item }}"
    state: absent
  with_fileglob:
    - "/etc/apt/sources.list.d/mariadb.list.old*"
  ignore_errors: true

- name: Install MariaDB
  apt:
    name: "{{ packages }}"
    state: present
    update_cache: true
  vars:
    packages:
      - mariadb-server
      - mariadb-client

- name: Install MariaDB DB conf
  template:
    src: my.cnf.j2
    dest: /etc/mysql/conf.d/db.cnf
    force: true
    mode: 0644

- name: Install MariaDB Supervisord conf
  template:
    src: supervisor.conf.j2
    dest: /etc/supervisor/conf.d/mariadb.conf
    force: true
    mode: 0644

- name: Disable MariaDB service
  service:
    name: "mysql"
    enabled: false
    state: stopped
  ignore_errors: true
