---
- name: prepare installer boot loader grub
  blockinfile:
    path: /etc/di-netboot-assistant/grub.cfg.HEAD
    insertbefore: "^menuentry 'Boot from local disk..'"
    marker: "# {mark} ANSIBLE MANAGED BLOCK netboot-installer"
    block: |
      menuentry 'Installer Debian bookworm (amd64) + preseed + lmn-desktop.yml' --unrestricted {
          linux (http,{{ ansible_default_ipv4.address }})/d-i/n-pkg/images/12/amd64/text/debian-installer/amd64/linux auto=true priority=critical \
          url=tftp://{{ ansible_default_ipv4.address }}/d-i/bookworm/preseed.cfg_lmn-desktop \
          playbook=lmn-desktop.yml adpw='{{ gapw }}' ---
          initrd (http,{{ ansible_default_ipv4.address }})/d-i/n-pkg/images/12/amd64/text/debian-installer/amd64/initrd.gz
      }
  notify: rebuild di-netboot menu

- name: set git-daemon-export-ok for management repo
  copy:
    content: ""
    dest: "{{ playbook_dir }}/.git/git-daemon-export-ok"
    force: false
    group: ansible
    owner: ansible
    mode: 0644

- name: Create gitd systemd service file
  template:
    src: templates/lmn-netboot-git.service.j2
    dest: /lib/systemd/system/lmn-netboot-git.service

- name: start lmn-netboot-git service for installation playbook
  systemd:
    name: lmn-netboot-git
    enabled: true
    state: started

- name: provide preseed.cfg_lmn-desktop file
  template:
    src: templates/preseed.cfg_lmn-desktop.j2
    dest: /var/lib/tftpboot/d-i/bookworm/preseed.cfg_lmn-desktop
  notify: restart git service
