---
- name: Install gluster repository
  become: true
  ansible.builtin.dnf:
    name: centos-release-gluster9
    state: present
  register: _datastore_repo_gluster

- name: Enable required repositories
  become: true
  ansible.builtin.lineinfile:
    path: /etc/yum.repos.d/{{ item }}.repo
    line: enabled=1
    state: present
    regexp: "#?enabled=(0|1)"
  loop:
    - Rocky-AppStream
    - Rocky-PowerTools
  register: _datastore_repo_powertools

- name: Install datastore packages
  become: true
  when: ansible_distribution == "Rocky"
  ansible.builtin.dnf:
    state: present
    update_cache: "{{ _datastore_repo_powertools.changed or _datastore_repo_gluster.changed }}"
    name:
      - cryptsetup-luks
      - glusterfs
      - glusterfs-fuse
      - glusterfs-server
