---

- name: sysfsutils is installed
  ansible.builtin.apt:
    name:
      - sysfsutils
    state: present
  tags:
    - redis
    - packages
    - kernel

- name: Check possible values for THP
  ansible.builtin.assert:
    that: redis_sysctl_transparent_hugepage_enabled is in ['always', 'madvise', 'never']
    msg: "redis_sysctl_transparent_hugepage_enabled has incorrect value : '{{ redis_sysctl_transparent_hugepage_enabled }}' not in ['always', 'madvise', 'never']"
  tags:
    - redis
    - kernel

- name: "Set THP to {{ redis_sysctl_transparent_hugepage_enabled }} at boot"
  ansible.builtin.lineinfile:
    path: /etc/sysfs.conf
    line: kernel/mm/transparent_hugepage/enabled = {{ redis_sysctl_transparent_hugepage_enabled }}
    regexp: "kernel/mm/transparent_hugepage/enabled"
    create: yes
  tags:
    - redis
    - kernel

- name: "Set THP to {{ redis_sysctl_transparent_hugepage_enabled }} for this boot"
  ansible.builtin.shell:
    cmd: "echo '{{ redis_sysctl_transparent_hugepage_enabled }}' >> /sys/kernel/mm/transparent_hugepage/enabled"
  tags:
    - redis
    - kernel
