- name: make preseed directory available
  file:
    path: "{{ tftp_root }}/d-i/{{ di_dist }}"
    state: directory

- name: provide preseed file
  copy:
    src: /usr/share/doc/di-netboot-assistant/examples/preseed.cfg
    dest: "{{ tftp_root }}/d-i/{{ di_dist }}"
    force: no

- name: enable apt-cacher-ng for install-clients
  replace:
    dest: "{{ tftp_root }}/d-i/{{ di_dist }}/preseed.cfg"
    regexp: '^(d-i mirror/http/proxy string.*)$'
    replace: 'd-i mirror/http/proxy string http://{{ hostname }}:3142/'
    
- name: make the hostname resolvable from the LAN
  replace:
    path: /etc/hosts
    regexp: '^(127\.0\.1\.1.*)$'
    replace: '#\1\n{{ ipaddr_lan }}	{{ hostname }}'

- name: add auto pxe boot entry to di-netboot-assistant
  blockinfile:
    dest: /etc/di-netboot-assistant/pxelinux.HEAD
    insertbefore: EOF
    block: |
      TIMEOUT 100
      LABEL autoinstall
         MENU LABEL Debian {{ di_version }} (amd64) + preseed + kiosk.yml
         kernel ::/d-i/n-pkg/images/{{ di_version }}/amd64/text/debian-installer/amd64/linux
         append initrd=::/d-i/n-pkg/images/{{ di_version }}/amd64/text/debian-installer/amd64/initrd.gz auto=true priority=critical url=tftp://{{ hostname }} playbook=kiosk.yml ---

         #LABEL daily
         #MENU LABEL Debian daily (amd64) + preseed + kiosk.yml
         #kernel ::/d-i/n-a/daily/amd64/linux
         #append initrd=::/d-i/n-a/daily/amd64/initrd.gz auto=true priority=critical url=tftp://{{ hostname }} playbook=kiosk.yml ---
  notify: "rebuild di-netboot-assistant menu"

- name: add auto efi boot entry to di-netboot-assistant
  blockinfile:
    dest: /etc/di-netboot-assistant/grub.cfg.HEAD
    insertbefore: EOF
    block: |
      menuentry 'Debian {{ di_version }} (amd64) + preseed + kiosk.yml' {
         linux   /d-i/n-pkg/images/{{ di_version }}/amd64/text/debian-installer/amd64/linux auto=true priority=critical url=tftp://{{ hostname }} playbook=kiosk.yml ---
         initrd  /d-i/n-pkg/images/{{ di_version }}/amd64/text/debian-installer/amd64/initrd.gz
      }

      #menuentry 'Debian daily (amd64) + preseed + kiosk.yml' {
      #   linux   /d-i/n-a/daily/amd64/linux auto=true priority=critical url=tftp://{{ hostname }} playbook=kiosk.yml ---
      #   initrd  /d-i/n-a/daily/amd64/initrd.gz
      #}
  notify: "rebuild di-netboot-assistant menu"