- name: Remove MariaDB Repository File
  file:
    path: /etc/apt/sources.list.d/mariadb.list
    state: absent

- name: Remove MariaDB Repository File
  file:
    path: /etc/apt/sources.list.d/mirror_rackspace_com_mariadb_repo_10_6_ubuntu.list
    state: absent

- name: Remove MariaDB Repository File
  file:
    path: /etc/apt/sources.list.d/deb_mariadb_org_10_6_ubuntu.list
    state: absent

- name: Add MariaDB Repository Key
  apt_key:
    url: https://packages.jingrow.cloud/jingrow.gpg.key
    state: present

- name: Add MariaDB Repository
  apt_repository:
    repo: deb https://packages.jingrow.cloud/mariadb/10.6 focal main
    state: present
    update_cache: true

- name: Update APT Cache
  apt:
    update_cache: yes

- name: Use Debian Unattended Package Installation Mode
  shell: export DEBIAN_FRONTEND=noninteractive
  changed_when: false

- name: Install MariaDB
  apt:
    pkg:
      - mariadb-server-10.6
      - mariadb-server-core-10.6
      - mariadb-client-10.6
      - mariadb-client-core-10.6
      - libmariadbclient18
    state: latest

- name: Set Open Files Count Limit for MariaDB
  lineinfile:
    dest: /lib/systemd/system/mariadb.service
    regexp: '^LimitNOFILE(\s*)=(\s*)\d+'
    line: 'LimitNOFILE = infinity'
    insertafter: '\[Service\]'
    state: present

- name: Restart MariaDB Service
  systemd:
    daemon_reload: true
    name: mariadb
    state: restarted
    enabled: yes
