## 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
##  > }
##
## To build an initial customized image run 'livebuilder.sh'.
## A systemd-timer will do this every week automatically.
---
- name: apply configuration to the livebox
  hosts: all
  remote_user: ansible
  become: true

  vars:
#    ansible_connection: local
    extra_pkgs:
      - lighttpd
      - nfs-kernel-server
      - atftpd
      - di-netboot-assistant
      - apt-cacher-ng
    extra_pkgs_bpo: []

    live_desktop: # [] # use an empty list to skip iso images
      - gnome
      - kde
      - standard

    live_url: 'https://cdimage.debian.org/cdimage/release/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
      - standard-edu

    di_dist: "{{ ansible_distribution_release }}"
    di_version: "{{ ansible_distribution_major_version }}"
    di_pkg: "debian-installer-{{ di_version }}-netboot-amd64"
    boot_params:
      - boot=live
      - components
      - locales=de_DE.UTF-8
      - keyboard-layouts=de
      - live-config.timezone=Europe/Berlin
      - swap=true
      - quiet
      - splash
      - user-default-groups=audio,cdrom,dip,video,plugdev,netdev,dialout
      - modprobe.blacklist=nvme
#      - libata.force=disable
#      - 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 + '.iso' }) }}"
      loop: "{{ live_desktop }}"

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