From 9406e7ddfbd59da4ecbe42dc016163a7bf257d1b Mon Sep 17 00:00:00 2001 From: Josh Lay Date: Wed, 3 Jun 2020 21:15:43 -0500 Subject: [PATCH] tuned - add custom profile support, udev/io sched. example --- play.yml | 17 +++++++++++++ roles/tuned/defaults/main.yml | 3 +++ roles/tuned/handlers/main.yml | 5 ++++ .../tuned/tasks/configure-custom-profile.yml | 25 +++++++++++++++++++ roles/tuned/tasks/main.yml | 9 +++++++ roles/tuned/templates/custom_profile.conf.j2 | 12 +++++++++ 6 files changed, 71 insertions(+) create mode 100644 roles/tuned/defaults/main.yml create mode 100644 roles/tuned/handlers/main.yml create mode 100644 roles/tuned/tasks/configure-custom-profile.yml create mode 100644 roles/tuned/templates/custom_profile.conf.j2 diff --git a/play.yml b/play.yml index 740deab..dd93ece 100644 --- a/play.yml +++ b/play.yml @@ -1,5 +1,22 @@ --- - hosts: all + vars: + tuned_base_profile: "network-latency" + tuned_custom_profile: + name: tweaks + sections: + - name: main + params: + - option: summary + value: "Custom tuned profile created by jlay - virt. IO scheduler, TCP, etc" + - option: include + value: "{{ tuned_base_profile }}" + - name: disk + params: + - option: devices_udev_regex + value: "(ID_MODEL=QEMU_HARDDISK)|(ID_VENDOR=HC)" + - option: elevator + value: "mq-deadline" roles: - {role: bootstrap} - {role: tmp-mount-fix} diff --git a/roles/tuned/defaults/main.yml b/roles/tuned/defaults/main.yml new file mode 100644 index 000000000..9596cea --- /dev/null +++ b/roles/tuned/defaults/main.yml @@ -0,0 +1,3 @@ +--- +tuned_base_profile: "network-latency" +tuned_custom_profile: "default-custom-profile" diff --git a/roles/tuned/handlers/main.yml b/roles/tuned/handlers/main.yml new file mode 100644 index 000000000..fb4ce78 --- /dev/null +++ b/roles/tuned/handlers/main.yml @@ -0,0 +1,5 @@ +--- +- name: restart tuned + service: + name: tuned + state: restarted diff --git a/roles/tuned/tasks/configure-custom-profile.yml b/roles/tuned/tasks/configure-custom-profile.yml new file mode 100644 index 000000000..087be78 --- /dev/null +++ b/roles/tuned/tasks/configure-custom-profile.yml @@ -0,0 +1,25 @@ +# borrowed from https://github.com/giovtorres/ansible-role-tuned/ +# trivially changed based on style preferences +--- +- name: create custom tuned profile directory + file: + path: "/etc/tuned/{{ tuned_custom_profile.name }}" + state: directory + owner: root + group: root + mode: 0755 + +- name: copy custom profile configuration file + template: + src: custom_profile.conf.j2 + dest: "/etc/tuned/{{ tuned_custom_profile.name }}/tuned.conf" + owner: root + group: root + mode: 0644 + notify: restart tuned + register: tuned_custom_profile_template + +- name: set custom tuned profile + command: "/usr/sbin/tuned-adm profile {{ tuned_custom_profile.name }}" + when: + - tuned_custom_profile_template is changed diff --git a/roles/tuned/tasks/main.yml b/roles/tuned/tasks/main.yml index 6a41998..d483264 100644 --- a/roles/tuned/tasks/main.yml +++ b/roles/tuned/tasks/main.yml @@ -13,3 +13,12 @@ name: tuned enabled: yes state: started + +- name: get active tuned profile + command: /usr/sbin/tuned-adm active + register: tuned_active + changed_when: false + ignore_errors: true + +- name: deploy {{ tuned_custom_profile }} based on {{ tuned_base_profile }} + include: configure-custom-profile.yml diff --git a/roles/tuned/templates/custom_profile.conf.j2 b/roles/tuned/templates/custom_profile.conf.j2 new file mode 100644 index 000000000..8ed68ea --- /dev/null +++ b/roles/tuned/templates/custom_profile.conf.j2 @@ -0,0 +1,12 @@ +{{ ansible_managed | comment }} +# +# tuned '{{ tuned_custom_profile.name }}' configuration +# + +{% for section in tuned_custom_profile.sections %} +[{{ section.name }}] +{% for item in section.params %} +{{ item.option }}={{ item.value }} +{% endfor %} + +{% endfor %}