diff options
| author | Ahmed AbdelHalim <[email protected]> | 2026-07-09 23:20:14 +0200 |
|---|---|---|
| committer | Ahmed AbdelHalim <[email protected]> | 2026-07-10 00:38:48 +0200 |
| commit | e28eda14b15bb439479906d70e33145001a827cf (patch) | |
| tree | 0a46b0bbab2ab58a91e29669a9f5519e817d551a | |
| parent | 2a62cabd9a521dbc7ec14b260230bf4b95fdfb12 (diff) | |
Extract logind lid configuration into it's own role
24 files changed, 109 insertions, 36 deletions
diff --git a/configure.yml b/configure.yml index f64046c6..1fee0ac1 100644 --- a/configure.yml +++ b/configure.yml @@ -9,6 +9,7 @@ - role: "locales" - role: "timezone" - role: "font" + - role: "logind" - role: "bash" - role: "man" - role: "which" @@ -106,6 +107,7 @@ - role: "pve-storage" - role: "locales" - role: "timezone" + - role: "logind" - role: "bash" - role: "man" - role: "jq" diff --git a/host_vars/laptop.local.yml b/host_vars/laptop.local.yml Binary files differindex 18eabeb7..8674e040 100644 --- a/host_vars/laptop.local.yml +++ b/host_vars/laptop.local.yml diff --git a/host_vars/laptop.local.yml.example b/host_vars/laptop.local.yml.example index ea11d74e..c3f4ff18 100644 --- a/host_vars/laptop.local.yml.example +++ b/host_vars/laptop.local.yml.example @@ -38,3 +38,5 @@ firefox_policies_override: fonts_extra: - "fonts-font-awesome" - "fonts-google-fira" + +logind_lid_ac_action: "ignore" diff --git a/host_vars/macbook.local.yml b/host_vars/macbook.local.yml Binary files differindex 0d1f1561..9bdb3650 100644 --- a/host_vars/macbook.local.yml +++ b/host_vars/macbook.local.yml diff --git a/host_vars/macbook.local.yml.example b/host_vars/macbook.local.yml.example index 8e2586ca..cb8aae6d 100644 --- a/host_vars/macbook.local.yml.example +++ b/host_vars/macbook.local.yml.example @@ -52,3 +52,5 @@ firefox_extra_extensions: installation_mode: "force_installed" install_url: "https://addons.mozilla.org/firefox/downloads/latest/tabby-window-tab-manager/latest.xpi" + +logind_lid_ac_action: "ignore" diff --git a/host_vars/pve.local.yml b/host_vars/pve.local.yml Binary files differindex 6b2e4ba1..8f2a6a54 100644 --- a/host_vars/pve.local.yml +++ b/host_vars/pve.local.yml diff --git a/host_vars/pve.local.yml.example b/host_vars/pve.local.yml.example index 88a60b5a..60b6060c 100644 --- a/host_vars/pve.local.yml.example +++ b/host_vars/pve.local.yml.example @@ -16,4 +16,4 @@ pve_storage_device: "/dev/sda4" restic_version: "0.19.0" ethtool_wol_interface: "eth0" -ethtool_lid_ac_action: "ignore" +logind_lid_ac_action: "ignore" diff --git a/molecule/archlinux-gnome/converge.yml b/molecule/archlinux-gnome/converge.yml index 3c93488e..aad8ab85 100644 --- a/molecule/archlinux-gnome/converge.yml +++ b/molecule/archlinux-gnome/converge.yml @@ -61,6 +61,7 @@ - role: "yay" - role: "font" - role: "which" + - role: "logind" - role: "bash" - role: "alacritty" - role: "man" diff --git a/molecule/archlinux/converge.yml b/molecule/archlinux/converge.yml index 79a4ff07..bc691e8d 100644 --- a/molecule/archlinux/converge.yml +++ b/molecule/archlinux/converge.yml @@ -61,6 +61,7 @@ - role: "yay" - role: "font" - role: "which" + - role: "logind" - role: "bash" - role: "alacritty" - role: "man" diff --git a/molecule/debian/converge.yml b/molecule/debian/converge.yml index 701eeedd..d3d3f4d0 100644 --- a/molecule/debian/converge.yml +++ b/molecule/debian/converge.yml @@ -68,6 +68,7 @@ roles: - role: "locales" - role: "timezone" + - role: "logind" - role: "bash" - role: "man" - role: "jq" diff --git a/molecule/proxmox/converge.yml b/molecule/proxmox/converge.yml index e590d49d..3d66282a 100644 --- a/molecule/proxmox/converge.yml +++ b/molecule/proxmox/converge.yml @@ -55,6 +55,7 @@ - role: "pve-storage" - role: "locales" - role: "timezone" + - role: "logind" - role: "bash" - role: "man" - role: "jq" diff --git a/molecule/ubuntu/converge.yml b/molecule/ubuntu/converge.yml index b3589a5b..43100898 100644 --- a/molecule/ubuntu/converge.yml +++ b/molecule/ubuntu/converge.yml @@ -58,6 +58,7 @@ roles: - role: "locales" - role: "timezone" + - role: "logind" - role: "bash" - role: "man" - role: "jq" diff --git a/roles/ethtool/defaults/main.yml b/roles/ethtool/defaults/main.yml index 8da62da2..61cfd43e 100644 --- a/roles/ethtool/defaults/main.yml +++ b/roles/ethtool/defaults/main.yml @@ -1,3 +1,2 @@ --- ethtool_wol_interface: "eth0" -ethtool_lid_ac_action: "suspend" diff --git a/roles/ethtool/handlers/main.yml b/roles/ethtool/handlers/main.yml index 88cc1a15..f2b4275a 100644 --- a/roles/ethtool/handlers/main.yml +++ b/roles/ethtool/handlers/main.yml @@ -4,8 +4,3 @@ 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 ef5aefad..8f6ce206 100644 --- a/roles/ethtool/meta/argument_specs.yml +++ b/roles/ethtool/meta/argument_specs.yml @@ -6,15 +6,3 @@ 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/meta/main.yml b/roles/ethtool/meta/main.yml index de7f32a3..e33a01b3 100644 --- a/roles/ethtool/meta/main.yml +++ b/roles/ethtool/meta/main.yml @@ -1,5 +1,6 @@ --- -dependencies: [] +dependencies: + - role: "logind" galaxy_info: author: "a14m" description: "Install ethtool and enable Wake-on-LAN via systemd service" diff --git a/roles/ethtool/tasks/main.yml b/roles/ethtool/tasks/main.yml index f92d052e..c9c67648 100644 --- a/roles/ethtool/tasks/main.yml +++ b/roles/ethtool/tasks/main.yml @@ -26,17 +26,3 @@ # WoL service fails in containers — ethtool_wol_interface does not exist - "molecule-notest" -- 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 deleted file mode 100644 index 722e3a8a..00000000 --- a/roles/ethtool/templates/logind.conf.j2 +++ /dev/null @@ -1,2 +0,0 @@ -[Login] -HandleLidSwitchExternalPower={{ ethtool_lid_ac_action }} diff --git a/roles/logind/defaults/main.yml b/roles/logind/defaults/main.yml new file mode 100644 index 00000000..bff32a33 --- /dev/null +++ b/roles/logind/defaults/main.yml @@ -0,0 +1,5 @@ +--- +logind_lid_ac_action: "suspend" +logind_lid_battery_action: "suspend" +logind_idle_action: "suspend" +logind_idle_delay: 0 diff --git a/roles/logind/handlers/main.yml b/roles/logind/handlers/main.yml new file mode 100644 index 00000000..617bb197 --- /dev/null +++ b/roles/logind/handlers/main.yml @@ -0,0 +1,6 @@ +--- +- name: "Reload systemd-logind" + become: true + ansible.builtin.systemd_service: + name: "systemd-logind" + state: "restarted" diff --git a/roles/logind/meta/argument_specs.yml b/roles/logind/meta/argument_specs.yml new file mode 100644 index 00000000..4dca7643 --- /dev/null +++ b/roles/logind/meta/argument_specs.yml @@ -0,0 +1,44 @@ +--- +argument_specs: + main: + options: + logind_lid_battery_action: + type: "str" + description: "HandleLidSwitch — action when lid closed on battery" + default: "suspend" + choices: + - "ignore" + - "suspend" + - "hibernate" + - "hybrid-sleep" + - "suspend-then-hibernate" + - "lock" + - "poweroff" + logind_lid_ac_action: + type: "str" + description: "HandleLidSwitchExternalPower — action when lid closed on AC power" + default: "suspend" + choices: + - "ignore" + - "suspend" + - "hibernate" + - "hybrid-sleep" + - "suspend-then-hibernate" + - "lock" + - "poweroff" + logind_idle_action: + type: "str" + description: "IdleAction — action after idle timeout" + default: "suspend" + choices: + - "ignore" + - "suspend" + - "hibernate" + - "hybrid-sleep" + - "suspend-then-hibernate" + - "lock" + - "poweroff" + logind_idle_delay: + type: "int" + description: "IdleActionSec in seconds (0 disables idle action)" + default: 0 diff --git a/roles/logind/meta/main.yml b/roles/logind/meta/main.yml new file mode 100644 index 00000000..7ab91f4a --- /dev/null +++ b/roles/logind/meta/main.yml @@ -0,0 +1,18 @@ +--- +dependencies: + - role: "systemd" +galaxy_info: + author: "a14m" + description: "Configure systemd-logind lid switch and idle behavior" + license: "MIT" + min_ansible_version: "2.18" + platforms: + - name: "ArchLinux" + versions: + - "all" + - name: "Ubuntu" + versions: + - "noble" + - name: "Debian" + versions: + - "bookworm" diff --git a/roles/logind/tasks/main.yml b/roles/logind/tasks/main.yml new file mode 100644 index 00000000..3b5aad5c --- /dev/null +++ b/roles/logind/tasks/main.yml @@ -0,0 +1,17 @@ +--- +- 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 systemd-logind" + become: true + ansible.builtin.template: + src: "logind.conf.j2" + dest: "/etc/systemd/logind.conf.d/override.conf" + owner: "root" + group: "root" + mode: "0644" + notify: "Reload systemd-logind" diff --git a/roles/logind/templates/logind.conf.j2 b/roles/logind/templates/logind.conf.j2 new file mode 100644 index 00000000..b1269b15 --- /dev/null +++ b/roles/logind/templates/logind.conf.j2 @@ -0,0 +1,5 @@ +[Login] +HandleLidSwitch={{ logind_lid_battery_action }} +HandleLidSwitchExternalPower={{ logind_lid_ac_action }} +IdleAction={{ logind_idle_action }} +IdleActionSec={{ logind_idle_delay }} |
