---
- name: Add Redis PPA repository (Focal)
  apt_repository:
    repo: "ppa:chris-lea/redis-server"
    update_cache: true
  when: ansible_distribution_release == 'focal'

- name: Install Redis
  apt:
    name: redis-server

- name: Install Redis Conf
  template:
    src: redis.conf.j2
    dest: /etc/redis/redis.conf
    force: true
    owner: "redis"
    mode: 0644

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

- name: Disable Redis services
  service:
    name: "{{ item }}"
    enabled: false
    state: stopped
  ignore_errors: true
  with_items:
    - "redis-server"
    - "redis"
