--- - name: check if wifi-connection(-file) exists stat: path: /etc/NetworkManager/system-connections/SchulWLAN.nmconnection register: stat_result - name: connect device to internal wifi "schulnetz" block: - name: add hidden wifi command: nmcli connection add type wifi con-name SchulWLAN ifname {{ wifi_ifname }} ssid {{ wlan-ssid }} - name: modify wifi password command: nmcli connection modify SchulWLAN wifi-sec.key-mgmt wpa-psk wifi-sec.psk "{{ wlan-pw }}" - name: autoconnect wifi command: nmcli connection modify SchulWLAN connection.autoconnect yes - name: modify wifi hidden command: nmcli connection modify SchulWLAN 802-11-wireless.hidden yes - name: connect wifi command: nmcli connection up SchulWLAN when: not stat_result.stat.exists and ("notebooks" in group_names) ...