From c475723f52c2613a4f935c0d07952cca551bc809 Mon Sep 17 00:00:00 2001 From: Josh Lay Date: Sun, 27 Jul 2025 12:34:44 -0500 Subject: [PATCH] tuned: release-dependent profile basedir, lint --- roles/tuned/defaults/main.yml | 2 ++ roles/tuned/handlers/main.yml | 13 +++++++--- .../tuned/tasks/configure-custom-profile.yml | 20 +++++++-------- roles/tuned/tasks/main.yml | 25 +++++++++++-------- 4 files changed, 35 insertions(+), 25 deletions(-) diff --git a/roles/tuned/defaults/main.yml b/roles/tuned/defaults/main.yml index 9596cea..ec4d612 100644 --- a/roles/tuned/defaults/main.yml +++ b/roles/tuned/defaults/main.yml @@ -1,3 +1,5 @@ --- tuned_base_profile: "network-latency" tuned_custom_profile: "default-custom-profile" +# profiles are expected in a subdirectory past 2.23.0; default using package facts +tuned_amdgpu_profile_dir: "{{ '/etc/tuned' if ansible_facts['packages']['tuned'][0]['version'] is version('2.23.0', '<') else '/etc/tuned/profiles' }}" diff --git a/roles/tuned/handlers/main.yml b/roles/tuned/handlers/main.yml index 9a9188c..6828688 100644 --- a/roles/tuned/handlers/main.yml +++ b/roles/tuned/handlers/main.yml @@ -1,8 +1,13 @@ --- -- name: restart tuned - service: +- name: Restart + ansible.builtin.service: name: tuned state: restarted + become: true + listen: tuned_restart -- name: enable tuned profile - command: "/usr/sbin/tuned-adm profile {{ tuned_custom_profile.name }}" +- name: Enable Profile + ansible.builtin.command: "/usr/sbin/tuned-adm profile {{ tuned_custom_profile.name }}" + become: true + changed_when: true # handler, assumed this would be making/realizing changes + listen: tuned_enable diff --git a/roles/tuned/tasks/configure-custom-profile.yml b/roles/tuned/tasks/configure-custom-profile.yml index 6f1286a..fe9b40f 100644 --- a/roles/tuned/tasks/configure-custom-profile.yml +++ b/roles/tuned/tasks/configure-custom-profile.yml @@ -1,22 +1,22 @@ --- -- name: create custom tuned profile directory +- name: Ensure profile directory become: true - file: - path: "/etc/tuned/{{ tuned_custom_profile.name }}" + ansible.builtin.file: + path: "{{ (tuned_amdgpu_profile_dir, tuned_custom_profile.name) | path_join }}" state: directory owner: root group: root - mode: 0755 + mode: '0755' -- name: copy custom profile configuration file +- name: Profile configuration become: true - template: + ansible.builtin.template: src: custom_profile.conf.j2 - dest: "/etc/tuned/{{ tuned_custom_profile.name }}/tuned.conf" + dest: "{{ (tuned_amdgpu_profile_dir, tuned_custom_profile.name, 'tuned.conf') | path_join }}" owner: root group: root - mode: 0644 + mode: '0644' notify: - - restart tuned - - enable tuned profile + - tuned_restart + - tuned_enable register: tuned_custom_profile_template diff --git a/roles/tuned/tasks/main.yml b/roles/tuned/tasks/main.yml index c75baee..b32b20a 100644 --- a/roles/tuned/tasks/main.yml +++ b/roles/tuned/tasks/main.yml @@ -1,14 +1,14 @@ --- -- name: update apt caches +- name: Update apt caches become: true - apt: + ansible.builtin.apt: update_cache: true when: (ansible_os_family in ["Debian"] ) -- name: install packages +- name: Install packages become: true - package: + ansible.builtin.package: name: "{{ item }}" state: present with_items: @@ -16,20 +16,23 @@ - tuned-utils # - tuned-profiles-realtime # only on Fedora? not on centos 8 stream -- name: start service +- name: Gather Package Facts # 'tuned' release determines profile location + ansible.builtin.package_facts: + +- name: Start service become: true - service: + ansible.builtin.service: name: tuned enabled: true state: started -- name: get active tuned profile +- name: Get active tuned profile become: true - command: /usr/sbin/tuned-adm active + ansible.builtin.command: /usr/sbin/tuned-adm active register: tuned_active changed_when: false ignore_errors: true -- name: deploy custom tuned profiles - include_tasks: configure-custom-profile.yml - when: (ansible_distribution in ["CentOS" , "Red Hat Enterprise Linux", "RedHat", "Fedora" ] and not is_atomic) +- name: Deploy custom tuned profiles + ansible.builtin.include_tasks: configure-custom-profile.yml + when: not ansible_local.os.is_atomic