#####################################
### someone's ansible provisioner ###
#####################################
# Part of: https://git.somenet.org/root/pub/somesible.git
# 2017-2025 by someone <someone@somenet.org>
#
---
- name: install needed tools
  apt:
    pkg:
      - "{{grub_pkg}}"
      - "grub-pc-bin"
    state: present
    policy_rc_d: 101
  when: grub_setup | bool
  tags: "online"
  ignore_errors: "{{ignore_online_errors | bool}}"


- name: setup grub-defaults
  copy:
    src: "{{item}}"
    dest: "/etc/default/grub"
  with_first_found:
    - "{{lookup('env','PWD')}}/host_files/{{inventory_hostname}}/{{role_name}}/grub"
    - "{{lookup('env','PWD')}}/group_files/{{group_files_group}}/{{role_name}}/grub"
    - "{{lookup('env','PWD')}}/group_files/all/{{role_name}}/grub"
    - "default/grub"
  when: grub_setup | bool
  notify: update-grub


- name: setup grub protections
  template:
    src: "{{item}}"
    dest: "/etc/grub.d/10_linux"
    mode: 0755
    owner: "root"
    group: "root"
  with_first_found:
    - "{{lookup('env','PWD')}}/host_files/{{inventory_hostname}}/{{role_name}}/10_linux.j2"
    - "{{lookup('env','PWD')}}/group_files/{{group_files_group}}/{{role_name}}/10_linux.j2"
    - "{{lookup('env','PWD')}}/group_files/all/{{role_name}}/10_linux.j2"
    - "templates/10_linux.j2"
  when: grub_setup | bool
  notify: update-grub
