I'm trying to disable transparent_hugepage in the kernel. Which according to this article means adding the substring transparent_hugepage=never
to the GRUB_CMDLINE_LINUX
variable in /etc/default/grub
.
My attempt at doing that looks like:
- name: disable transparent_hugepage
ansible.builtin.lineinfile:
path: /etc/default/grub
regexp: '^(GRUB_CMDLINE_LINUX="[^"]+)"'
line: '\g<1> transparent_hugepage=never"'
backrefs: yes
That however adds the substring every time ansible runs, not only when it is missing.
i.e.
# grep CMD /etc/default/grub
GRUB_CMDLINE_LINUX="resume=/dev/mapper/cs-swap rd.lvm.lv=cs/root rd.lvm.lv=cs/swap rhgb quiet transparent_hugepage=never transparent_hugepage=never"
Surely there must be a better way to handle that than trying to do something fancy with regex negative lookahead?
I tried the lookahead approach using:
regexp: '^(GRUB_CMDLINE_LINUX="[^"]+)(?! transparent_hugepage=never)"'
but it behaves the same.