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 <noreply@anthropic.com>
This commit is contained in:
Fabio Scotto di Santolo
2026-05-13 23:44:14 +02:00
parent a12e646234
commit 3a2ce58c7d

View File

@@ -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] tags: [packages, nvidia]
ansible.builtin.lineinfile: ansible.builtin.lineinfile:
path: /etc/default/grub path: /etc/default/grub
regexp: '^GRUB_CMDLINE_LINUX=' backrefs: true
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"' regexp: '^(GRUB_CMDLINE_LINUX="(?!.*{{ item | regex_escape }}).*)"$'
state: present line: '\1 {{ item }}"'
loop:
- nouveau.modeset=0
- nvidia-drm.modeset=1
register: nymph_grub_cmdline
- name: Regenerate GRUB configuration - name: Regenerate GRUB configuration
tags: [packages, nvidia] tags: [packages, nvidia]
ansible.builtin.command: grub-mkconfig -o /boot/grub/grub.cfg ansible.builtin.command: grub-mkconfig -o /boot/grub/grub.cfg
changed_when: true changed_when: true
when: nymph_grub_cmdline is changed
- name: Configure NVIDIA power management for hybrid graphics - name: Configure NVIDIA power management for hybrid graphics
tags: [packages, nvidia] tags: [packages, nvidia]