Skip to content

Commit

Permalink
fix: Add /etc/default/grub if missing (#93)
Browse files Browse the repository at this point in the history
* Generate default grub with template regardless of ostree
  • Loading branch information
spetrosi authored Mar 12, 2024
1 parent 2164f48 commit 3c9a77c
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
25 changes: 25 additions & 0 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,31 @@
use: "{{ (__bootloader_is_ostree | d(false)) |
ternary('ansible.posix.rhel_rpm_ostree', omit) }}"

- name: Get stat of {{ __bootloader_default_grub }}
stat:
path: "{{ __bootloader_default_grub }}"
register: __bootloader_default_grub_stat

- name: If missing, add {{ __bootloader_default_grub }}
when: not __bootloader_default_grub_stat.stat.exists
block:
- name: Get bootloader args of the default kernel
shell: >-
set -euo pipefail;
grubby --info=DEFAULT | grep -oP 'args=\K(.*)'
register: __bootloader_default_args
changed_when: false

- name: Generate {{ __bootloader_default_grub }}
vars:
grub_cmdline_linux: "{{ __bootloader_default_args.stdout }}"
template:
src: etc_default_grub.j2
dest: "{{ __bootloader_default_grub }}"
owner: root
group: root
mode: 0644

- name: Determine platform type
stat:
path: /sys/firmware/efi
Expand Down
13 changes: 13 additions & 0 deletions templates/etc_default_grub.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{{ ansible_managed | comment }}
{{ "system_role:bootloader" | comment(prefix="", postfix="") }}
GRUB_TIMEOUT={{ bootloader_timeout }}
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_CMDLINE_LINUX={{ grub_cmdline_linux }}
GRUB_DISABLE_RECOVERY="true"
{% if not (ansible_facts['os_family'] == 'RedHat' and
ansible_facts['distribution_version'] is version('7', '>=')) %}
GRUB_ENABLE_BLSCFG=true
{% endif %}
1 change: 1 addition & 0 deletions tests/roles/linux-system-roles.bootloader/templates

0 comments on commit 3c9a77c

Please sign in to comment.