From 3a2ce58c7d76ed0aad7c7ccf5b0573d88847f3de Mon Sep 17 00:00:00 2001 From: Fabio Scotto di Santolo Date: Wed, 13 May 2026 23:44:14 +0200 Subject: [PATCH] Append NVIDIA params to GRUB cmdline instead of overwriting Previously the task hardcoded GRUB_CMDLINE_LINUX to a fixed string containing nymph's rd.luks.uuid, rootflags and apparmor parameters, clobbering whatever the host had. Switch to an idempotent lineinfile-with-backrefs loop that appends nouveau.modeset=0 and nvidia-drm.modeset=1 only when missing, preserving the existing kernel cmdline. grub-mkconfig now runs only when the cmdline changed. Co-Authored-By: Claude Sonnet 4.6 --- ansible/roles/profile_desktop_host/tasks/nymph.yml | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/ansible/roles/profile_desktop_host/tasks/nymph.yml b/ansible/roles/profile_desktop_host/tasks/nymph.yml index 167c82a..7098329 100644 --- a/ansible/roles/profile_desktop_host/tasks/nymph.yml +++ b/ansible/roles/profile_desktop_host/tasks/nymph.yml @@ -1,16 +1,21 @@ --- -- name: Configure GRUB kernel parameters for NVIDIA hybrid graphics +- name: Ensure NVIDIA kernel parameters are present in GRUB cmdline tags: [packages, nvidia] ansible.builtin.lineinfile: path: /etc/default/grub - regexp: '^GRUB_CMDLINE_LINUX=' - line: 'GRUB_CMDLINE_LINUX="rd.luks.uuid=1e15d159-5d05-4a1f-9639-ac200dff9f9c rootflags=subvol=@ apparmor=1 security=apparmor nouveau.modeset=0 nvidia-drm.modeset=1"' - state: present + backrefs: true + regexp: '^(GRUB_CMDLINE_LINUX="(?!.*{{ item | regex_escape }}).*)"$' + line: '\1 {{ item }}"' + loop: + - nouveau.modeset=0 + - nvidia-drm.modeset=1 + register: nymph_grub_cmdline - name: Regenerate GRUB configuration tags: [packages, nvidia] ansible.builtin.command: grub-mkconfig -o /boot/grub/grub.cfg changed_when: true + when: nymph_grub_cmdline is changed - name: Configure NVIDIA power management for hybrid graphics tags: [packages, nvidia]