generated from nicolabelluti/template-ansible
Added gpu_governor role
This commit is contained in:
@@ -0,0 +1,99 @@
|
||||
- name: Check if the governor is already installed
|
||||
ansible.builtin.command:
|
||||
argv:
|
||||
- pacman
|
||||
- -Qq
|
||||
- cyan-skillfish-governor-smu
|
||||
register: is_gov_installed
|
||||
changed_when: false
|
||||
failed_when: false
|
||||
|
||||
- name: Build and install the governor from the AUR
|
||||
when: is_gov_installed.rc != 0
|
||||
block:
|
||||
- name: Create temporary dir for build
|
||||
ansible.builtin.tempfile:
|
||||
state: directory
|
||||
suffix: csgov
|
||||
register: gov_tmp
|
||||
|
||||
- name: Download the AUR snapshot
|
||||
ansible.builtin.get_url:
|
||||
url: "https://aur.archlinux.org/cgit/aur.git/snapshot/cyan-skillfish-governor-smu.tar.gz"
|
||||
dest: "{{ gov_tmp.path }}/cyan-skillfish-governor-smu.tar.gz"
|
||||
|
||||
- name: Extract the snapshot
|
||||
ansible.builtin.unarchive:
|
||||
src: "{{ gov_tmp.path }}/cyan-skillfish-governor-smu.tar.gz"
|
||||
dest: "{{ gov_tmp.path }}"
|
||||
remote_src: true
|
||||
|
||||
- name: Read the package metadata
|
||||
ansible.builtin.slurp:
|
||||
src: "{{ gov_tmp.path }}/cyan-skillfish-governor-smu/.SRCINFO"
|
||||
register: gov_srcinfo
|
||||
|
||||
- name: Extract build and runtime dependencies
|
||||
ansible.builtin.set_fact:
|
||||
gov_build_deps: >-
|
||||
{{ (gov_srcinfo.content | b64decode)
|
||||
| regex_findall('(?m)^\s*(?:make|check)?depends(?:_\w+)?\s*=\s*([^\s<>=]+)')
|
||||
| unique }}
|
||||
|
||||
- name: Ensure build prerequisites are present
|
||||
become: true
|
||||
ansible.builtin.pacman:
|
||||
name: "{{ ['base-devel', 'fakeroot'] + gov_build_deps }}"
|
||||
state: present
|
||||
|
||||
# Rust build, expect several minutes on Zen 2.
|
||||
- name: Build the package (no install)
|
||||
ansible.builtin.command:
|
||||
argv:
|
||||
- makepkg
|
||||
- --noconfirm
|
||||
chdir: "{{ gov_tmp.path }}/cyan-skillfish-governor-smu"
|
||||
environment:
|
||||
PKGDEST: "{{ gov_tmp.path }}/cyan-skillfish-governor-smu"
|
||||
|
||||
- name: Locate built package(s)
|
||||
ansible.builtin.find:
|
||||
paths: "{{ gov_tmp.path }}/cyan-skillfish-governor-smu"
|
||||
patterns: "*.pkg.tar.zst"
|
||||
excludes: "*-debug-*"
|
||||
file_type: file
|
||||
register: gov_built_pkgs
|
||||
|
||||
# Install with root, but OUTSIDE makepkg
|
||||
- name: Install built package(s)
|
||||
become: true
|
||||
ansible.builtin.command:
|
||||
argv:
|
||||
- pacman
|
||||
- -U
|
||||
- --noconfirm
|
||||
- "{{ item.path }}"
|
||||
loop: "{{ gov_built_pkgs.files }}"
|
||||
notify: Restart the GPU governor
|
||||
|
||||
always:
|
||||
- name: Remove temporary directory
|
||||
ansible.builtin.file:
|
||||
path: "{{ gov_tmp.path }}"
|
||||
state: absent
|
||||
when: gov_tmp.path is defined
|
||||
|
||||
- name: Deploy the governor configuration
|
||||
become: true
|
||||
ansible.builtin.template:
|
||||
src: config.toml.j2
|
||||
dest: /etc/cyan-skillfish-governor-smu/config.toml
|
||||
mode: '0644'
|
||||
notify: Restart the GPU governor
|
||||
|
||||
- name: Enable and start the GPU governor
|
||||
become: true
|
||||
ansible.builtin.systemd_service:
|
||||
name: cyan-skillfish-governor-smu
|
||||
enabled: true
|
||||
state: started
|
||||
Reference in New Issue
Block a user