---
- name: Configure WLAN for devices
  community.general.nmcli:
    conn_name: "{{ ssid }}"
    type: wifi
    ssid: "{{ ssid }}"
    ifname: "{{ ansible_interfaces | select('search', 'wl.+') | first }}"
    wifi_sec:
      key-mgmt: wpa-psk
      psk: "{{ wifipasswd }}"
    autoconnect: true
    state: present
  when: |
    not run_in_installer|default(false)|bool and
    ansible_interfaces | select('search', 'wl.+') | first is defined

- name: Provide WLAN config during installation
  template:
    src: ssid.nmconnection.j2
    dest: "/etc/NetworkManager/system-connections/{{ ssid }}.nmconnection"
    mode: '0600'
  when: |
    run_in_installer|default(false)|bool and
    ansible_interfaces | select('search', 'wl.+') | first is defined
