summaryrefslogtreecommitdiffstats
path: root/roles/logind
diff options
context:
space:
mode:
authorAhmed Abdelhalim <[email protected]>2026-07-09 23:20:14 +0200
committerAhmed Abdelhalim <[email protected]>2026-07-10 00:38:48 +0200
commit31ab4af71809028695e747cc717dae0e45a21e8e (patch)
tree0a46b0bbab2ab58a91e29669a9f5519e817d551a /roles/logind
parent1cbb9df950175e698e1edc87953e8f4bfb22b88a (diff)
Extract logind lid configuration into it's own role
Diffstat (limited to 'roles/logind')
-rw-r--r--roles/logind/defaults/main.yml5
-rw-r--r--roles/logind/handlers/main.yml6
-rw-r--r--roles/logind/meta/argument_specs.yml44
-rw-r--r--roles/logind/meta/main.yml18
-rw-r--r--roles/logind/tasks/main.yml17
-rw-r--r--roles/logind/templates/logind.conf.j25
6 files changed, 95 insertions, 0 deletions
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 }}