---
# Setup requirements
- name: Install packages related to wifi
  ansible.builtin.apt:
    name:
      - systemd-resolved
      - firmware-realtek # for our wifi sticks

- name: Provide service to enable WiFi on boot
  ansible.builtin.copy:
    dest: /etc/systemd/system/enable-wifi.service
    mode: '0644'
    content: |
      [Unit]
      Description=Switch WiFi on
      After=NetworkManager.service

      [Service]
      Type=oneshot
      ExecStart=/usr/bin/nmcli radio wifi on

      [Install]
      WantedBy=multi-user.target
  when: wlan_enable_on_boot

- name: Enable the enable-wifi service
  ansible.builtin.systemd:
    name: enable-wifi.service
    enabled: true
    daemon_reload: true
  when: wlan_enable_on_boot

# lmn_wlan - Initial configuration based on the WLAN variable
# When WLAN type is set to PSK
- name: Configure WPA-PSK
  ansible.builtin.include_tasks: wpa-psk.yaml
  when: wlan == 'psk'

# When WLAN type is set to EAP-TLS (802.1x)
- name: Configure WPA-Enterprise (EAP-TLS)
  ansible.builtin.include_tasks: eap-tls_check-certificate.yaml
  when: wlan == 'eap-tls'
