---
# IPv6
- name: Check IPv6 Disabled
  shell: cat /boot/firmware/cmdline.txt | grep -c 'ipv6.disable' || true
  register: pi_ipv6_disabled
  changed_when: false # Do not mark as 'changed'

- name: Add IPv6 Disabled
  replace: dest=/boot/firmware/cmdline.txt regexp='(\s*)$' replace=' ipv6.disable=1'
  when: pi_ipv6_disabled.stdout == "0"
  notify: "Reboot Server"

# CPUSet
- name: Check cpuset cgroup
  shell: cat /boot/firmware/cmdline.txt | grep -c 'cgroup_enable=cpuset' || true
  register: pi_cgroup_cpuset
  changed_when: false # Do not mark as 'changed'

- name: Add cpuset cgroup
  replace: dest=/boot/firmware/cmdline.txt regexp='(\s*)$' replace=' cgroup_enable=cpuset'
  when: pi_cgroup_cpuset.stdout == "0"
  notify: "Reboot Server"

# Memory
- name: Check memory cgroup enabled
  shell: cat /boot/firmware/cmdline.txt | grep -c 'cgroup_enable=memory' || true
  register: pi_cgroup_memory_enable
  changed_when: false # Do not mark as 'changed'

- name: Add memory cgroup enabled
  replace: dest=/boot/firmware/cmdline.txt regexp='(\s*)$' replace=' cgroup_enable=memory'
  when: pi_cgroup_memory_enable.stdout == "0"
  notify: "Reboot Server"

# Memory Group
- name: Check memory cgroup
  shell: cat /boot/firmware/cmdline.txt | grep -c 'cgroup_memory' || true
  register: pi_cgroup_memory
  changed_when: false # Do not mark as 'changed'

- name: Add memory cgroup
  replace: dest=/boot/firmware/cmdline.txt regexp='(\s*)$' replace=' cgroup_memory=1'
  when: pi_cgroup_memory.stdout == "0"
  notify: "Reboot Server"
