---
- name: Ensure policy file exist on host
  ansible.builtin.copy:
    src: "files/{{ policy_name }}.te"
    dest: "/tmp/{{ policy_name }}.te"
    group: "root"
    mode: "0644"
    owner: "root"

- name: Compile SELinux policy module
  ansible.builtin.command: |
    checkmodule -M -m -o \
      "/tmp/squirro-{{ policy_name }}.mod" "/tmp/{{ policy_name }}.te"
  args:
    creates: "/tmp/squirro-{{ policy_name }}.mod"

- name: Package SELinux policy module
  ansible.builtin.command: |
    semodule_package -o "/tmp/squirro-{{ policy_name }}.pp" \
      -m "/tmp/squirro-{{ policy_name }}.mod"
  args:
    creates: "/tmp/squirro-{{ policy_name }}.pp"

# Default priority is 400, needs to be lower
- name: Install SELinux policy module
  ansible.builtin.command: |
    semodule -i "/tmp/squirro-{{ policy_name }}.pp"
  changed_when: true
