diff options
| author | Ahmed Abdelhalim <[email protected]> | 2026-07-03 11:00:17 +0200 |
|---|---|---|
| committer | Ahmed Abdelhalim <[email protected]> | 2026-07-03 11:00:17 +0200 |
| commit | e2e2fd3a111dc307fb8e54dae9689ff901e7e9c1 (patch) | |
| tree | 9e36d5afa874fb50f05c9ce81ad7d5e475272103 /roles | |
| parent | 16c2395a58db566337224837df8dbe75d062baf6 (diff) | |
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
Diffstat (limited to 'roles')
| -rw-r--r-- | roles/ethtool/README.md | 9 | ||||
| -rw-r--r-- | roles/ethtool/defaults/main.yml | 1 | ||||
| -rw-r--r-- | roles/ethtool/handlers/main.yml | 6 | ||||
| -rw-r--r-- | roles/ethtool/meta/argument_specs.yml | 12 | ||||
| -rw-r--r-- | roles/ethtool/tasks/main.yml | 15 | ||||
| -rw-r--r-- | roles/ethtool/templates/logind.conf.j2 | 2 |
6 files changed, 43 insertions, 2 deletions
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 }} |
