---

- set_fact:
    percona__apt_config_package_file: "percona-release_latest.{{ ansible_distribution_release }}_all.deb"

- name: Add Percona's official GPG key
  apt_key:
    data: "{{ lookup('file', 'percona.asc') }}"

- name: Check if percona-release is installed
  command: "dpkg -l percona-release"
  failed_when: False
  changed_when: False
  register: percona__apt_config_package_installed

- name: Percona APT config package is available
  copy:
    src: "{{ percona__apt_config_package_file }}"
    dest: "/root/{{ percona__apt_config_package_file }}"
  when: not percona__apt_config_package_installed

# - include_role:
#     name: evolix/remount-usr

- name: Percona APT config package is installed from deb file
  apt:
    deb: "/root/{{ percona__apt_config_package_file }}"
    state: present
  register: percona__apt_config_deb
  when: not percona__apt_config_package_installed

- name: Percona APT config package is installed from repository
  apt:
    name: percona-release
    state: latest
  register: percona__apt_config_deb
  when: percona__apt_config_package_installed

- name: APT cache is up-to-date
  apt:
    update_cache: yes
  when: percona__apt_config_deb is changed

- include: xtrabackup.yml
  when: percona__install_xtrabackup
