Created
November 9, 2022 11:48
-
-
Save aderixon/16bc4191d1bbd5d21f8fd2717e56fd75 to your computer and use it in GitHub Desktop.
Adding kernelopts in GRUB 2 with Ansible
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# set kernel option via grub2 | |
# (e.g. to disable THP in EL8+) | |
# | |
# N.B. this code doesn't support updating the value of an existing setting (not fully idempotent); | |
# in that case it will add a duplicate entry that may or may not override the first. | |
# If you have a lot of settings to manipulate, it would be easier to explicitly override the entire kernelopts | |
# (or use regex_replace) | |
# | |
# assumes thp_setting contains the sysfs value for THP | |
# | |
- name: get kernel args | |
command: grub2-editenv - list | |
changed_when: false | |
check_mode: no | |
register: grubenv | |
when: ansible_distribution_major_version|int >= 8 | |
- name: disable THP in kernel args | |
shell: | | |
grub2-editenv - set "{{ grubenv.stdout_lines | select('match', 'kernelopts=') | list | first }} transparent_hugepage={{ thp_setting }}" | |
when: ansible_distribution_major_version|int >= 8 and ("transparent_hugepage=" + thp_setting) not in grubenv.stdout |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment