---

- name: "Add begin marker if missing"
  ansible.builtin.lineinfile:
    path: "{{ redis_conf_dir }}/redis.conf"
    line: "# BEGIN {{ redis_conf_marker_label }}"
    insertbefore: BOF
    create: yes
  tags:
    - redis

- name: "Add end marker if missing"
  ansible.builtin.lineinfile:
    path: "{{ redis_conf_dir }}/redis.conf"
    line: "# END {{ redis_conf_marker_label }}"
    insertbefore: "Generated by CONFIG REWRITE"
    create: yes
  tags:
    - redis

- name: "Create config if missing"
  ansible.builtin.blockinfile:
    path: "{{ redis_conf_dir }}/redis.conf"
    marker: "# {mark} {{ redis_conf_marker_label }}"
    block: "{{ lookup('ansible.builtin.template', '../templates/redis.conf.j2') }}"
    mode: "0640"
    owner: redis
    group: redis
    create: yes
  notify: "{{ redis_restart_handler_name }}"
  tags:
    - redis

- name: Config directory permissions are set
  ansible.builtin.file:
    dest: "{{ redis_conf_dir }}"
    mode: "0750"
    owner: redis
    group: redis
  tags:
    - redis

- name: Redis is running and enabled on boot.
  ansible.builtin.systemd:
    name: "{{ redis_systemd_name }}"
    enabled: yes
    state: started
  tags:
    - redis
