From e38e66b07fc370be094241dd749f3a20af542c71 Mon Sep 17 00:00:00 2001 From: Ahmed AbdelHalim Date: Thu, 26 Feb 2026 20:17:35 +0100 Subject: Fix auto-starting iwd on boot --- roles/network/tasks/main.yml | 28 ++++++++++++++++++++++++++++ roles/network/templates/iwd-wifi.psk.j2 | 2 ++ 2 files changed, 30 insertions(+) create mode 100644 roles/network/templates/iwd-wifi.psk.j2 (limited to 'roles/network') diff --git a/roles/network/tasks/main.yml b/roles/network/tasks/main.yml index 394ec688..a2358fe6 100644 --- a/roles/network/tasks/main.yml +++ b/roles/network/tasks/main.yml @@ -55,6 +55,16 @@ when: ansible_facts['is_chroot'] # noqa: command-instead-of-module module doesn't work inside chroot +- name: "Compute hex-encoded SSID for iwd filename" + # noqa: risky-shell-pipe since this is used early before bash configuration + # it is the exception and needed to ensure that iwd is working on Mac machines + # that only work with broadcom-wl and iwd + ansible.builtin.shell: + cmd: "printf '%s' '{{ network_wifi_ssid }}' | xxd -p | tr -d '\\n'" + register: network_wifi_hex_ssid + changed_when: false + when: network_wifi_ssid != "" + - name: "Configure NetworkManager" become: true notify: @@ -98,3 +108,21 @@ owner: "root" group: "root" when: network_wifi_ssid != "" + + - name: "Ensure /var/lib/iwd directory exists" + ansible.builtin.file: + path: "/var/lib/iwd" + state: "directory" + mode: "0700" + owner: "root" + group: "root" + when: network_wifi_ssid != "" + + - name: "Configure iwd known network for wifi auto-connect" + ansible.builtin.template: + src: "iwd-wifi.psk.j2" + dest: "/var/lib/iwd/={{ network_wifi_hex_ssid.stdout }}.psk" + mode: "0600" + owner: "root" + group: "root" + when: network_wifi_ssid != "" diff --git a/roles/network/templates/iwd-wifi.psk.j2 b/roles/network/templates/iwd-wifi.psk.j2 new file mode 100644 index 00000000..df1fc2c3 --- /dev/null +++ b/roles/network/templates/iwd-wifi.psk.j2 @@ -0,0 +1,2 @@ +[Security] +Passphrase={{ network_wifi_pass }} -- cgit v1.2.3