From e2e2fd3a111dc307fb8e54dae9689ff901e7e9c1 Mon Sep 17 00:00:00 2001 From: Ahmed Abdelhalim Date: Fri, 3 Jul 2026 11:00:17 +0200 Subject: Update ethtool to handle laptop lid suspend issues When using WoL with laptops (ex Lenovo) closing the lid suspends the laptop and breaks WoL, this is to allow configuring the lid behavior --- host_vars/pve.local.yml | Bin 848 -> 880 bytes host_vars/pve.local.yml.example | 3 +++ roles/ethtool/README.md | 9 +++++++-- roles/ethtool/defaults/main.yml | 1 + roles/ethtool/handlers/main.yml | 6 ++++++ roles/ethtool/meta/argument_specs.yml | 12 ++++++++++++ roles/ethtool/tasks/main.yml | 15 +++++++++++++++ roles/ethtool/templates/logind.conf.j2 | 2 ++ 8 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 roles/ethtool/templates/logind.conf.j2 diff --git a/host_vars/pve.local.yml b/host_vars/pve.local.yml index a9e89f47..74e4714a 100644 Binary files a/host_vars/pve.local.yml and b/host_vars/pve.local.yml differ diff --git a/host_vars/pve.local.yml.example b/host_vars/pve.local.yml.example index fa59020a..182eb39e 100644 --- a/host_vars/pve.local.yml.example +++ b/host_vars/pve.local.yml.example @@ -16,3 +16,6 @@ restic_version: "0.19.0" pve_admin_user: "admin" pve_admin_password: "changeme" + +ethtool_wol_interface: "eth0" +ethtool_lid_ac_action: "ignore" diff --git a/roles/ethtool/README.md b/roles/ethtool/README.md index c1902568..69f987ee 100644 --- a/roles/ethtool/README.md +++ b/roles/ethtool/README.md @@ -5,7 +5,8 @@ Installs ethtool and configures Wake-on-LAN (WoL) via a systemd service. ## Variables ```yaml -ethtool_wol_interface: "eth0" # Network interface to enable WoL on +ethtool_wol_interface: "eth0" # Network interface to enable WoL on +ethtool_lid_ac_action: "suspend" # HandleLidSwitchExternalPower (ignore/suspend/hibernate/lock/poweroff) ``` ## Usage @@ -38,7 +39,11 @@ Enables WoL on the NIC via ethtool on every boot. Add to your play with the corr ethtool_wol_interface: "enp0s25" ``` -### 3. Suspend the host +### 3. Lid behavior (laptops) + +Role configures `HandleLidSwitchExternalPower` via `ethtool_lid_ac_action` (default: `suspend`). Set to `ignore` for WoL use case — lid close on AC won't re-suspend after wake. No effect on desktops. + +### 4. Suspend the host WoL is most reliable from suspend (S3). Shutdown (S5) requires BIOS "WoL from S5" support. diff --git a/roles/ethtool/defaults/main.yml b/roles/ethtool/defaults/main.yml index 61cfd43e..8da62da2 100644 --- a/roles/ethtool/defaults/main.yml +++ b/roles/ethtool/defaults/main.yml @@ -1,2 +1,3 @@ --- ethtool_wol_interface: "eth0" +ethtool_lid_ac_action: "suspend" diff --git a/roles/ethtool/handlers/main.yml b/roles/ethtool/handlers/main.yml index 3360d709..88cc1a15 100644 --- a/roles/ethtool/handlers/main.yml +++ b/roles/ethtool/handlers/main.yml @@ -3,3 +3,9 @@ become: true ansible.builtin.systemd_service: daemon_reload: true + +- name: "Reload systemd-logind" + become: true + ansible.builtin.systemd_service: + name: "systemd-logind" + state: "restarted" diff --git a/roles/ethtool/meta/argument_specs.yml b/roles/ethtool/meta/argument_specs.yml index 8f6ce206..ef5aefad 100644 --- a/roles/ethtool/meta/argument_specs.yml +++ b/roles/ethtool/meta/argument_specs.yml @@ -6,3 +6,15 @@ argument_specs: type: "str" description: "Network interface to enable Wake-on-LAN on" default: "eth0" + ethtool_lid_ac_action: + type: "str" + description: "HandleLidSwitchExternalPower value" + default: "suspend" + choices: + - "ignore" + - "suspend" + - "hibernate" + - "hybrid-sleep" + - "suspend-then-hibernate" + - "lock" + - "poweroff" diff --git a/roles/ethtool/tasks/main.yml b/roles/ethtool/tasks/main.yml index 9d2dac60..d1832d0b 100644 --- a/roles/ethtool/tasks/main.yml +++ b/roles/ethtool/tasks/main.yml @@ -22,3 +22,18 @@ enabled: true state: "started" daemon_reload: true + +- name: "Ensure /etc/systemd/logind.conf.d exists" + become: true + ansible.builtin.file: + path: "/etc/systemd/logind.conf.d" + state: "directory" + mode: "0755" + +- name: "Configure lid switch on AC power" + become: true + ansible.builtin.template: + src: "logind.conf.j2" + dest: "/etc/systemd/logind.conf.d/wol.conf" + mode: "0644" + notify: "Reload systemd-logind" diff --git a/roles/ethtool/templates/logind.conf.j2 b/roles/ethtool/templates/logind.conf.j2 new file mode 100644 index 00000000..722e3a8a --- /dev/null +++ b/roles/ethtool/templates/logind.conf.j2 @@ -0,0 +1,2 @@ +[Login] +HandleLidSwitchExternalPower={{ ethtool_lid_ac_action }} -- cgit v1.2.3