Skip to content
This repository has been archived by the owner on Oct 28, 2024. It is now read-only.

Commit

Permalink
Merge pull request #3 from doenietzomoeilijk/gpu-passthrough-intel-only
Browse files Browse the repository at this point in the history
Use a slightly uglier but more reliable way of determining GRUB_CMDLINE_LINUX_DEFAULT
  • Loading branch information
stevenwoudstra authored Jun 10, 2024
2 parents 1b8649c + fbb1be4 commit 809b9e3
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions roles/grubcmdline/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,24 @@
changed_when: old_cmdline != kernel_cmdline | select() | sort | list
notify: "{{ kernel_restart_handler }}"

- name: Slurp /etc/default/grub
ansible.builtin.slurp:
path: /etc/default/grub
register: grub_result
become: true
- name: Look for the last occurance of GRUB_CMDLINE_LINUX_DEFAULT in grub config
# In some environments, the grub config contained multiple lines defining this
# value; the last one would "win", but the change in this play would be based
# on the first one that was found, with interesting consequences. Hence this
# slightly less pure but more reliable way of fetching that line.
ansible.builtin.shell:
cmd: >-
set -o pipefail
&& grep -E '^GRUB_CMDLINE_LINUX_DEFAULT' /etc/default/grub | tail -1
args:
executable: /usr/bin/bash
register: grub_cmdline_linux_default
changed_when: grub_cmdline_linux_default.rc != 0

- name: Set fact containing GRUB_CMDLINE_LINUX_DEFAULT
- name: Set fact containing the contents of GRUB_CMDLINE_LINUX_DEFAULT
ansible.builtin.set_fact:
grub_cmdline_linux_default: >-
{{ grub_result.content | b64decode | regex_search('^GRUB_CMDLINE_LINUX_DEFAULT.*$', multiline=True) | regex_replace('^GRUB_CMDLINE_LINUX_DEFAULT="(.*)"$', '\1') }}
{{ grub_cmdline_linux_default.stdout | regex_search('^GRUB_CMDLINE_LINUX_DEFAULT.*$', multiline=True) | regex_replace('^GRUB_CMDLINE_LINUX_DEFAULT="(.*)"$', '\1') }}
- name: Display GRUB_CMDLINE_DEFAULT
ansible.builtin.debug:
var: grub_cmdline_linux_default
Expand All @@ -33,7 +41,7 @@
# We use a regex here so you can remove parameters regardless of their value, e.g to remove iommu=on you
# could use the regex: ^iommu=
ansible.builtin.set_fact:
grub_cmdline_linux_remove: "{{ grub_cmdline_linux_default.split() | select('search', kernel_cmdline_remove_regex) | list }}"
wrub_cmdline_linux_remove: "{{ grub_cmdline_linux_default.split() | select('search', kernel_cmdline_remove_regex) | list }}"

- name: Display parameters to be removed
ansible.builtin.debug:
Expand Down

0 comments on commit 809b9e3

Please sign in to comment.