From e3e82df7e40b4716c2f81d7a65d4cbb95fe51eef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20Gon=C3=A7alves?= Date: Sat, 3 May 2025 15:39:13 +0100 Subject: feat(roles/_workstation): suspend role for user --- roles/_workstation/sleep/tasks/main.yml | 12 ++++++++++++ .../_workstation/sleep/templates/user-sleep@.service.j2 | 17 +++++++++++++++++ site.workstation.yml | 3 +++ 3 files changed, 32 insertions(+) create mode 100644 roles/_workstation/sleep/tasks/main.yml create mode 100644 roles/_workstation/sleep/templates/user-sleep@.service.j2 diff --git a/roles/_workstation/sleep/tasks/main.yml b/roles/_workstation/sleep/tasks/main.yml new file mode 100644 index 0000000..1842adf --- /dev/null +++ b/roles/_workstation/sleep/tasks/main.yml @@ -0,0 +1,12 @@ +--- + +- name: generate user-sleep system service + ansible.builtin.template: + src: user-sleep@.service.j2 + dest: /etc/systemd/system/user-sleep@.service + mode: "0755" + +- name: enable user-sleep system service + ansible.builtin.service: + name: user-sleep@1000 + enabled: true diff --git a/roles/_workstation/sleep/templates/user-sleep@.service.j2 b/roles/_workstation/sleep/templates/user-sleep@.service.j2 new file mode 100644 index 0000000..34d404d --- /dev/null +++ b/roles/_workstation/sleep/templates/user-sleep@.service.j2 @@ -0,0 +1,17 @@ +# managed by Ansible + +[Unit] +Description=sleep.target of a systemd user session +Before=suspend.target sleep.target hibernate.target +StopWhenUnneeded=yes + +[Service] +Type=oneshot +ExecStart=/usr/bin/systemctl --user start suspend.target +ExecStop=/usr/bin/systemctl --user stop suspend.target +User=%I +Environment=DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/%I/bus +RemainAfterExit=yes + +[Install] +WantedBy=suspend.target sleep.target hibernate.target diff --git a/site.workstation.yml b/site.workstation.yml index 4e1b724..76fc3a6 100644 --- a/site.workstation.yml +++ b/site.workstation.yml @@ -56,6 +56,9 @@ - role: _workstation/smartcard when: ansible_distribution in ["Archlinux", "OpenBSD"] + + - role: _workstation/sleep + when: ansible_distribution in ["Archlinux"] - role: _workstation/pipewire when: ansible_distribution in ["Archlinux"] - role: _workstation/cronie -- cgit v1.2.3