Files
env-ansible/tasks/workstation/linux/software/tlp.yml
T

83 lines
2.7 KiB
YAML

---
# 20260716 - Hyperling
# Attempt to save battery life by having a daemon tune the CPU and disable
# unneeded components like USB, Bluetooth, WiFi, etc when not in use.
## Variables ##
- name: Workstation | Linux | Software | TLP | Facts
set_fact:
tlp: "tlp"
tlp_rdw: "tlp-rdw"
tlp_extra: "smartmontools"
tlp_config: "/etc/tlp.conf"
tlp_service: "tlp"
ppd_package: "power-profiles-daemon"
ppd_service: "power-profiles-daemon"
acf_package: "auto-cpufreq"
acf_service: "auto-cpufreq"
## Conflicts ##
- name: Workstation | Linux | Software | TLP | Conflicts | Disable
service:
name: "{{ item }}"
state: stopped
enabled: false
loop:
- "{{ ppd_service }}"
- "{{ acf_service }}"
- name: Workstation | Linux | Software | TLP | Conflicts | Remove
package:
name: "{{ ppd_package }} {{ acf_package }}"
state: absent
## Install TLP + Associated Software ##
- name: Workstation | Linux | Software | TLP | Install
package:
name: "{{ tlp }} {{ tlp_rdw }} {{ tlp_smart }}"
update_cache: yes
## Configuration ##
# Device choices:
# - bluetooth
# - nfc
# - wifi
# - wwan
# Bluetooth and WiFi are not always used so disable on boot.
# NFC and WWAN (cellular) are never used so always disable.
- name: Workstation | Linux | Software | TLP | Config
lineinfile:
path: "{{ tlp_config }}"
regexp: '{{ item.key }}'
line: '{{ item.value }} # MANAGED BY ANSIBLE'
state: present
create: yes
backup: yes
loop:
- { "key": '^[\#]?DEVICES_TO_DISABLE_ON_STARTUP', "value": 'DEVICES_TO_DISABLE_ON_STARTUP="bluetooth nfc wifi wwan"'}
# Ensure these stay commented, once the device is booted the user is in control. #
- { "key": '^[\#]?DEVICES_TO_ENABLE_ON_STARTUP', "value": '#DEVICES_TO_ENABLE_ON_STARTUP=""'}
- { "key": '^[\#]?DEVICES_TO_ENABLE_ON_AC', "value": '#DEVICES_TO_ENABLE_ON_AC=""'}
- { "key": '^[\#]?DEVICES_TO_DISABLE_ON_BAT', "value": '#DEVICES_TO_DISABLE_ON_BAT=""'}
# Help preserve battery life by not fully charging. #
- { "key": '^[\#]?START_CHARGE_THRESH_BAT0', "value": '{{ "" if battery else "#" }}START_CHARGE_THRESH_BAT0=75'}
- { "key": '^[\#]?STOP_CHARGE_THRESH_BAT0', "value": '{{ "" if battery else "#" }}STOP_CHARGE_THRESH_BAT0=80'}
- { "key": '^[\#]?START_CHARGE_THRESH_BAT1', "value": '{{ "" if battery else "#" }}START_CHARGE_THRESH_BAT1=75'}
- { "key": '^[\#]?STOP_CHARGE_THRESH_BAT1', "value": '{{ "" if battery else "#" }}STOP_CHARGE_THRESH_BAT1=80'}
## Enable + Start ##
# Ensure the service is running and will run after reboot.
- name: Workstation | Linux | Software | TLP | Enable + Start
service:
name: "{{ tlp_service }}"
state: started
enabled: true