## This playbook deploys the LiveBox.
##
## The LiveBox provides Debian Live and Installer images on top
## of an already existing network with minimal modifications to
## existing infrastructure.  It does not provide DHCP; the idea
## is to chainload the LiveBox' menu (iPXE or Grub) from PXE
## infrastructure already in place.
##
## To chainload the LiveBox in iPXE use:
##  > item livebox Chainload Menu from LiveBox
##  > …
##  > :livebox chain tftp://livebox.lan/d-i/n-a/menu.ipxe
##
## To chainload the LiveBox in Grub use:
##  > menuentry 'Chainload Menu from LiveBox' {
##  >   configfile (tftp,livebox.lan)/d-i/n-a/grub/grub.cfg
##  > }
##
---
- name: apply configuration to the livebox
  hosts: all
  remote_user: ansible
  become: true

  vars:
    extra_pkgs:
      - lighttpd
      - nfs-kernel-server
    extra_pkgs_bpo:
      - atftpd
      - di-netboot-assistant
      - apt-cacher-ng

    live_desktop:
      - gnome
      - kde
      - standard

    live_url: 'https://cdimage.debian.org/cdimage/unofficial/non-free/cd-including-firmware/current-live/amd64/iso-hybrid/'

    # The edulive role generates customized Debian-Live images.
    # Make sure you have sufficient disk space available (~30GiB?).
    build_images:
      - gnome-edu

    di_dist: "{{ ansible_distribution_release }}"
    di_version: "{{ ansible_distribution_major_version }}"
    di_pkg: "debian-installer-{{ di_version }}-netboot-amd64"
    boot_params:
      - boot=live
      - netboot=nfs
      - components
      - locales=de_DE.UTF-8
      - keyboard-layouts=de
      - quiet
      - splash
#      - noroot

    ansible_python_interpreter: "/usr/bin/python3"

  pre_tasks:
    - name: preseed atftpd
      debconf:
        name: atftpd
        question: atftpd/basedir
        value: /var/lib/tftpboot
        vtype: string

    - name: find available iso images
      uri:
        url: "{{ live_url }}"
        return_content: true
      register: idx

    - name: find and set ISO image version
      set_fact:
        version: "{{ idx.content | regex_findall('debian-live-(\\d+\\.\\d+\\.\\d+)-amd64-', '\\1') | first }}"

    - name: define ISO image map
      set_fact:
        live_iso: "{{ live_iso | default({}) | combine({ item: 'debian-live-' + version + '-amd64-' + item + '+nonfree.iso' }) }}"
      loop: "{{ live_desktop }}"

  roles:
    - up2date_debian
    - netbootinstaller
    - aptcacher
    - debianlive
    - edulive