diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..485dee6 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea diff --git a/README.md b/README.md index 5f55a38..dea9cb5 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,49 @@ -# role-service-hardware_sensors +[//]: # (SPDX-License-Identifier: MIT) +# Role Name -On Linux hardware configure fan and temp sensors \ No newline at end of file +role-service-hardware_sensors + +# Description + +On Linux hardware configure fan and temp sensors. + +# Requirements + +Your target machines must be Linux. + +# Role Variables + +Per [defaults/main.yml](defaults/main.yml) this role is equipped to deal with Arch Linux and Debian. + +- `packages_linux_sensors_all_families`: Place package names in this list that are identical across all Linux flavors. While we do install packages we don't have any that have identical names across all Linux flavors so this variable defaults to an empty list. + ``` + packages_linux_sensors_all_families: [] + ``` +- `packages_linux_sensors_*`: Add package names to an operating system-specific list if it's unique to that operating system. The asterisk (`*`) is a placeholder for `ansible_facts['os_family'] | lower`. If `ansible_facts['os_family']` equals `Debian` then this becomes `debian` and the list turns into `packages_linux_sensors_debian`; same for `packages_linux_sensors_archlinux` etc. Note that for Arch Linux these are official packages only, not packages from the Arch User Repository. + ``` + packages_linux_sensors_archlinux: + - 'lm_sensors' + + packages_linux_sensors_debian: + - 'lm-sensors' + - 'fancontrol' + ``` + +# Dependencies + +None. + +# Example Playbook + +In your `playbook.yml` call it like so: + +``` +- name: 'Awesome playbook' + hosts: all + roles: + - 'role-service-hardware_sensors' +``` + +# License + +MIT diff --git a/defaults/main.yml b/defaults/main.yml new file mode 100644 index 0000000..eb63cc7 --- /dev/null +++ b/defaults/main.yml @@ -0,0 +1,10 @@ +# SPDX-License-Identifier: MIT +packages_linux_sensors_all_families: + + +packages_linux_sensors_archlinux: + - 'lm_sensors' + +packages_linux_sensors_debian: + - 'lm-sensors' + - 'fancontrol' diff --git a/files/etc/fancontrol-fans-2-4-5-7-bound-to-cpu-die-temp b/files/etc/fancontrol-fans-2-4-5-7-bound-to-cpu-die-temp new file mode 100644 index 0000000..ed746f4 --- /dev/null +++ b/files/etc/fancontrol-fans-2-4-5-7-bound-to-cpu-die-temp @@ -0,0 +1,12 @@ +# SPDX-License-Identifier: MIT +# Configuration file generated by pwmconfig, changes will be lost +INTERVAL=10 +# DEVPATH=hwmon1=devices/platform/nct6775.656 +# DEVNAME=hwmon1=nct6799 +FCTEMPS=/sys/devices/platform/nct6775.[[:print:]]*/hwmon/hwmon[[:print:]]*/pwm7=/sys/devices/platform/nct6775.[[:print:]]*/hwmon/hwmon[[:print:]]*/temp7_input /sys/devices/platform/nct6775.[[:print:]]*/hwmon/hwmon[[:print:]]*/pwm5=/sys/devices/platform/nct6775.[[:print:]]*/hwmon/hwmon[[:print:]]*/temp7_input /sys/devices/platform/nct6775.[[:print:]]*/hwmon/hwmon[[:print:]]*/pwm2=/sys/devices/platform/nct6775.[[:print:]]*/hwmon/hwmon[[:print:]]*/temp7_input /sys/devices/platform/nct6775.[[:print:]]*/hwmon/hwmon[[:print:]]*/pwm4=/sys/devices/platform/nct6775.[[:print:]]*/hwmon/hwmon[[:print:]]*/temp7_input +FCFANS=/sys/devices/platform/nct6775.[[:print:]]*/hwmon/hwmon[[:print:]]*/pwm7=/sys/devices/platform/nct6775.[[:print:]]*/hwmon/hwmon[[:print:]]*/fan7_input /sys/devices/platform/nct6775.[[:print:]]*/hwmon/hwmon[[:print:]]*/pwm5=/sys/devices/platform/nct6775.[[:print:]]*/hwmon/hwmon[[:print:]]*/fan5_input /sys/devices/platform/nct6775.[[:print:]]*/hwmon/hwmon[[:print:]]*/pwm2=/sys/devices/platform/nct6775.[[:print:]]*/hwmon/hwmon[[:print:]]*/fan2_input /sys/devices/platform/nct6775.[[:print:]]*/hwmon/hwmon[[:print:]]*/pwm4=/sys/devices/platform/nct6775.[[:print:]]*/hwmon/hwmon[[:print:]]*/fan4_input +MINTEMP=/sys/devices/platform/nct6775.[[:print:]]*/hwmon/hwmon[[:print:]]*/pwm7=70 /sys/devices/platform/nct6775.[[:print:]]*/hwmon/hwmon[[:print:]]*/pwm5=70 /sys/devices/platform/nct6775.[[:print:]]*/hwmon/hwmon[[:print:]]*/pwm2=70 /sys/devices/platform/nct6775.[[:print:]]*/hwmon/hwmon[[:print:]]*/pwm4=70 +MAXTEMP=/sys/devices/platform/nct6775.[[:print:]]*/hwmon/hwmon[[:print:]]*/pwm7=90 /sys/devices/platform/nct6775.[[:print:]]*/hwmon/hwmon[[:print:]]*/pwm5=90 /sys/devices/platform/nct6775.[[:print:]]*/hwmon/hwmon[[:print:]]*/pwm2=90 /sys/devices/platform/nct6775.[[:print:]]*/hwmon/hwmon[[:print:]]*/pwm4=90 +MINSTART=/sys/devices/platform/nct6775.[[:print:]]*/hwmon/hwmon[[:print:]]*/pwm7=100 /sys/devices/platform/nct6775.[[:print:]]*/hwmon/hwmon[[:print:]]*/pwm5=100 /sys/devices/platform/nct6775.[[:print:]]*/hwmon/hwmon[[:print:]]*/pwm2=100 /sys/devices/platform/nct6775.[[:print:]]*/hwmon/hwmon[[:print:]]*/pwm4=100 +MINSTOP=/sys/devices/platform/nct6775.[[:print:]]*/hwmon/hwmon[[:print:]]*/pwm7=100 /sys/devices/platform/nct6775.[[:print:]]*/hwmon/hwmon[[:print:]]*/pwm5=100 /sys/devices/platform/nct6775.[[:print:]]*/hwmon/hwmon[[:print:]]*/pwm2=100 /sys/devices/platform/nct6775.[[:print:]]*/hwmon/hwmon[[:print:]]*/pwm4=100 +MINPWM=/sys/devices/platform/nct6775.[[:print:]]*/hwmon/hwmon[[:print:]]*/pwm7=100 /sys/devices/platform/nct6775.[[:print:]]*/hwmon/hwmon[[:print:]]*/pwm5=100 /sys/devices/platform/nct6775.[[:print:]]*/hwmon/hwmon[[:print:]]*/pwm2=100 /sys/devices/platform/nct6775.[[:print:]]*/hwmon/hwmon[[:print:]]*/pwm4=100 diff --git a/files/etc/modprobe.d/lm-sensors.conf b/files/etc/modprobe.d/lm-sensors.conf new file mode 100644 index 0000000..a3c9f8e --- /dev/null +++ b/files/etc/modprobe.d/lm-sensors.conf @@ -0,0 +1,2 @@ +# SPDX-License-Identifier: MIT +options nct6775 force_id=0xd802 diff --git a/files/etc/modules-load.d/lm-sensors.conf b/files/etc/modules-load.d/lm-sensors.conf new file mode 100644 index 0000000..456aca4 --- /dev/null +++ b/files/etc/modules-load.d/lm-sensors.conf @@ -0,0 +1,2 @@ +# SPDX-License-Identifier: MIT +nct6775 diff --git a/handlers/main.yml b/handlers/main.yml new file mode 100644 index 0000000..01cd9ad --- /dev/null +++ b/handlers/main.yml @@ -0,0 +1,10 @@ +# SPDX-License-Identifier: MIT +- name: 'Reboot machine' + ansible.builtin.reboot: + test_command: 'qm list' + +- name: 'Restart fancontrol.service' + ansible.builtin.service: + name: 'fancontrol.service' + state: 'restarted' + enabled: true diff --git a/meta/main.yml b/meta/main.yml new file mode 100644 index 0000000..c3b9258 --- /dev/null +++ b/meta/main.yml @@ -0,0 +1,9 @@ +# SPDX-License-Identifier: MIT +galaxy_info: + author: 'hygienic-books' + description: 'On Linux hardware configure fan and temp sensors' + license: MIT + min_ansible_version: 2.18.1 + galaxy_tags: + - 'sensors' +dependencies: [] diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..f4658be --- /dev/null +++ b/tasks/main.yml @@ -0,0 +1,3 @@ +# SPDX-License-Identifier: MIT +- import_tasks: 'mainboard-amd-am5-b650m-hdv_m.2.yml' + when: 'ansible_facts[''product_name''] | lower == ''b650m-hdv/m.2''' diff --git a/tasks/mainboard-amd-am5-b650m-hdv_m.2.yml b/tasks/mainboard-amd-am5-b650m-hdv_m.2.yml new file mode 100644 index 0000000..bf2ed51 --- /dev/null +++ b/tasks/mainboard-amd-am5-b650m-hdv_m.2.yml @@ -0,0 +1,38 @@ +# SPDX-License-Identifier: MIT +- name: 'If mainboard is ASRock B650M-HDV/M.2 (with Nuvoton NCT6796D-S SuperIO chip) and OS is a Linux flavor and install Linux-specific packages for sensors and fan control' + when: 'ansible_facts[''system''] | lower == ''linux''' + ansible.builtin.package: + name: '{{ packages_linux_sensors_all_families }}' + state: 'present' + +- name: 'If mainboard is ASRock B650M-HDV/M.2 (with Nuvoton NCT6796D-S SuperIO chip) and ''os_family'' is ''{{ ansible_facts[''os_family''] | lower }}'' install {{ ansible_facts[''os_family''] | lower }}-specific packages for sensors and fan control' + ansible.builtin.package: + name: '{{ vars[''packages_linux_sensors_'' + ansible_facts[''os_family''] | lower] }}' + state: 'present' + +- name: 'If mainboard is ASRock B650M-HDV/M.2 (with Nuvoton NCT6796D-S SuperIO chip) add fan control config' + loop_control: + loop_var: 'file' + index_var: 'i' + label: 'Store ''{{ file.dst }}'' {{ file.purpose_human_readable }}' + loop: + - { src: 'etc/fancontrol-fans-2-4-5-7-bound-to-cpu-die-temp', dst: '/etc/fancontrol', purpose_human_readable: 'to supply sane fan control settings' } + ansible.builtin.copy: + src: '{{ file.src }}' + dest: '{{ file.dst }}' + notify: + - 'Restart fancontrol.service' + +- name: 'If mainboard is ASRock B650M-HDV/M.2 (with Nuvoton NCT6796D-S SuperIO chip) add kernel module config' + loop_control: + loop_var: 'file' + index_var: 'i' + label: 'Store ''/{{ file.path }}'' {{ file.purpose_human_readable }}' + loop: + - { path: 'etc/modules-load.d/lm-sensors.conf', purpose_human_readable: 'to auto-load the ''nct6775'' kernel module on boot' } + - { path: 'etc/modprobe.d/lm-sensors.conf', purpose_human_readable: 'for the ''nct6775'' kernel module to work with this mainboard' } + ansible.builtin.copy: + src: '{{ file.path }}' + dest: '/{{ file.path }}' + notify: + - 'Reboot machine'