# platform = multi_platform_rhel,multi_platform_rhv,multi_platform_fedora,multi_platform_ol,SUSE Linux Enterprise 15,multi_platform_almalinux
# reboot = false
# strategy = restrict
# complexity = low
# disruption = low

- name: "{{{ rule_title }}} - Find /etc/grub.d/ files"
  ansible.builtin.find:
    paths:
      - /etc/grub.d/
    follow: true
  register: result_grub_d

- name: "{{{ rule_title }}} - Ensure SELinux Not Disabled in /etc/grub.d/ files"
  ansible.builtin.replace:
    dest: "{{ item.path }}"
    regexp: (selinux|enforcing)=0
  with_items:
    - "{{ result_grub_d.files }}"

- name: "{{{ rule_title }}} - Check if /etc/grub2.cfg exists"
  ansible.builtin.stat:
    path: /etc/grub2.cfg
  register: result_grub2_cfg_present

- name: "{{{ rule_title }}} - Check if /etc/default/grub exists"
  ansible.builtin.stat:
    path: /etc/default/grub
  register: result_default_grub_present

- name: "{{{ rule_title }}} - Ensure SELinux Not Disabled in /etc/grub2.cfg"
  ansible.builtin.replace:
    dest: "/etc/grub2.cfg"
    regexp: (selinux|enforcing)=0
  when:
    - result_grub2_cfg_present.stat.exists

- name: "{{{ rule_title }}} - Ensure SELinux Not Disabled in /etc/default/grub"
  ansible.builtin.replace:
    dest: "/etc/default/grub"
    regexp: (selinux|enforcing)=0
  when:
    - result_default_grub_present.stat.exists
