---
# CentOS related tasks

- name: Add Remi repo
  dnf:
    name: https://rpms.remirepo.net/enterprise/remi-release-{{ ansible_distribution_major_version|int }}.rpm
    state: latest
    disable_gpg_check: yes
    validate_certs: no
  when: redis_daemon == "redis"

- name: Ensure Redis is installed.
  dnf:
    name: redis
    state: present
    enablerepo: remi
  when: redis_daemon == "redis"

- name: Add keydb repo
  dnf:
    name: https://download.keydb.dev/pkg/open_source/rpm/centos7/x86_64/keydb-latest-1.el7.x86_64.rpm
    disable_gpg_check: yes 
    validate_certs: no
  when: redis_daemon == "keydb"

- name: Ensure KeyDB is installed.
  dnf:
    name: keydb
    state: present
  when: redis_daemon == "keydb"

- name: Install redis_ha.te script
  copy:
    src: "{{ role_path }}/files/redis_ha.te"
    dest: /tmp/redis_ha.te
    mode: 0644

- name: Selinux... checkmodule redis_ha.te
  shell: checkmodule -m -M -o /tmp/redis_ha.mod /tmp/redis_ha.te

- name: Selinux... semodule_package redis_ha.mod
  shell: semodule_package --outfile /tmp/redis_ha.pp --module /tmp/redis_ha.mod

- name: Selinux... semodule redis_ha.pp
  shell: semodule -i /tmp/redis_ha.pp

- name: Selinux... add custom port
  shell: semanage port -a -t redis_port_t -p tcp {{ redis_port }}
  when: redis_port != "6379"
  ignore_errors: yes
