---
# This playbook deploys the installbox on a minimal installation.

- name: apply configuration to the installbox
  hosts: all
  remote_user: ansible
  become: yes
  vars:
    if_lan: ""           #  ← interface name here, like:  ens3 or enp2s0"
    if_wan: "{{ ansible_default_ipv4.interface }}"
    hostname: "{{ ansible_hostname }}" # change this to not use the DNS-provided name
    ipaddr_lan: 192.168.0.10
    dhcp_range: 192.168.0.50,192.168.0.150,2h
    dhcp_list: "{{ lookup('sequence', 'start=50 end=150 format=192.168.0.%d', wantlist=True) }}"
    tftp_root: "/var/lib/tftpboot"
    deb_mirror: "cdn-fastly.deb.debian.org" # SRV records ("deb.debian.org") do not work with squid
    di_dist: "buster"
    di_version: "10"
    di_pkg: "debian-installer-{{ di_version }}-netboot-amd64"
    ansible_user: ansible
    repo_dir: "/home/{{ ansible_user }}/kiosk"

  pre_tasks:
    - name: validate if interface is available
      fail:
        msg: "Interface {{ if_lan }} does not exist or is already used."
      when: if_lan not in ansible_interfaces or if_lan == if_wan

  roles:
    - up2date-debian
    - two-interface-shorewall
    - dhcp-dns-dnsmasq
    - transparent-squid
    - tftp-netboot-installer
    - preseed-installer
    - installbox2kiosk

  post_tasks:
    - name: make sure hostname is set correctly in /etc/hosts
      replace:
        path: /etc/hosts
        regexp: '(127.0.1.1\s+){{ ansible_hostname }}(\s+.*)?$'
        replace: '\1{{ hostname }}\2'

    - name: make sure hostname is set correctly in /etc/hostname
      replace:
        path: /etc/hostname
        regexp: '{{ ansible_hostname }}'
        replace: '{{ hostname }}'

    - name: set hostname
      hostname:
        name: "{{ hostname }}"