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

Commit

Permalink
Use a slightly uglier but more reliable way of determining GRUB_CMDLI…
Browse files Browse the repository at this point in the history
…NE_LINUX_DEFAULT.
  • Loading branch information
doenietzomoeilijk committed Jun 10, 2024
1 parent af72cef commit f934195
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions roles/grubcmdline/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,19 @@
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: Set fact containing GRUB_CMDLINE_LINUX_DEFAULT
- name: Look for the last occurance of GRUB_CMDLINE_LINUX_DEFAULT in grub config

Check failure on line 18 in roles/grubcmdline/tasks/main.yml

View workflow job for this annotation

GitHub Actions / lint / Ansible 2.12 lint

no-changed-when Commands should not change things if nothing needs doing

Check failure on line 18 in roles/grubcmdline/tasks/main.yml

View workflow job for this annotation

GitHub Actions / lint / Ansible 2.14 lint

no-changed-when

Commands should not change things if nothing needs doing.

Check failure on line 18 in roles/grubcmdline/tasks/main.yml

View workflow job for this annotation

GitHub Actions / lint / Ansible 2.14 lint

risky-shell-pipe

Shells that use pipes should set the pipefail option.
# 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: >-
grep -E '^GRUB_CMDLINE_LINUX_DEFAULT' /etc/default/grub | tail -1
register: 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 Down

0 comments on commit f934195

Please sign in to comment.