diff --git a/roles/laptop/files/lib/systemd/system/battery-charge-threshold.service b/roles/laptop/files/lib/systemd/system/battery-charge-threshold.service new file mode 100644 index 0000000..be18e16 --- /dev/null +++ b/roles/laptop/files/lib/systemd/system/battery-charge-threshold.service @@ -0,0 +1,12 @@ +[Unit] +Description=Set the battery charge threshold +After=multi-user.target +StartLimitBurst=0 + +[Service] +Type=oneshot +Restart=on-failure +ExecStart=/bin/bash -c 'echo 80 > /sys/class/power_supply/BAT0/charge_control_end_threshold' + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/roles/laptop/tasks/battery.yml b/roles/laptop/tasks/battery.yml new file mode 100644 index 0000000..c6ad9bb --- /dev/null +++ b/roles/laptop/tasks/battery.yml @@ -0,0 +1,18 @@ +- name: Check if laptop has option to limit battery + stat: + path: /sys/class/power_supply/BAT0/charge_control_end_threshold + register: battery_limiter_available + +- when: battery_limiter_available.stat.exists + block: + - name: Copy service to limit battery charge + become: yes + copy: + src: lib/systemd/system/battery-charge-threshold.service + dest: /lib/systemd/system/battery-charge-threshold.service + + - name: Enable battery limit service + become: yes + systemd: + name: battery-charge-threshold + enabled: yes diff --git a/roles/laptop/tasks/main.yml b/roles/laptop/tasks/main.yml new file mode 100644 index 0000000..cdda24d --- /dev/null +++ b/roles/laptop/tasks/main.yml @@ -0,0 +1 @@ +- import_tasks: battery.yml