Skip to content

Commit

Permalink
feat: Add and Remove kernels, add with --copy-defaults (#75)
Browse files Browse the repository at this point in the history
* feat: Add the ability to create kernels

* Add ability to add/remove kernels, and do --copy-defaults when adding

* Update README

* Refactor and fix tests and linters

* Add conf dirs for SLES, it is required by sap roles
  • Loading branch information
spetrosi authored Jan 9, 2024
1 parent 433771f commit 97ef015
Show file tree
Hide file tree
Showing 10 changed files with 764 additions and 169 deletions.
102 changes: 52 additions & 50 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Role Name
# bootloader

[![ansible-lint.yml](https://github.com/linux-system-roles/bootloader/actions/workflows/ansible-lint.yml/badge.svg)](https://github.com/linux-system-roles/bootloader/actions/workflows/ansible-lint.yml) [![ansible-test.yml](https://github.com/linux-system-roles/bootloader/actions/workflows/ansible-test.yml/badge.svg)](https://github.com/linux-system-roles/bootloader/actions/workflows/ansible-test.yml) [![codeql.yml](https://github.com/linux-system-roles/bootloader/actions/workflows/codeql.yml/badge.svg)](https://github.com/linux-system-roles/bootloader/actions/workflows/codeql.yml) [![markdownlint.yml](https://github.com/linux-system-roles/bootloader/actions/workflows/markdownlint.yml/badge.svg)](https://github.com/linux-system-roles/bootloader/actions/workflows/markdownlint.yml) [![python-unit-test.yml](https://github.com/linux-system-roles/bootloader/actions/workflows/python-unit-test.yml/badge.svg)](https://github.com/linux-system-roles/bootloader/actions/workflows/python-unit-test.yml) [![woke.yml](https://github.com/linux-system-roles/bootloader/actions/workflows/woke.yml/badge.svg)](https://github.com/linux-system-roles/bootloader/actions/workflows/woke.yml)

Expand All @@ -25,60 +25,39 @@ With this variable, list kernels and their command line parameters that you want
Required keys:

1. `kernel` - with this, specify the kernel to update settings for.
You can specify one or more kernels using the following criteria, you can use only single criteria at a time:
Each list should specify the same kernel using one or multiple keys.

* `kernel_path` - a specific kernel path, can be a list of paths
* `kernel_index` - a specific kernel index, can be a list of indexes
* `kernel_title` - a specific kernel title, can be a list of titles
If you want to you add a kernel, you must specify three keys - `path`, `title`, `initrd`.

If you want to modify or remove a kerne, you can specify one or more key.

You can also specify `DEFAULT` or `ALL` to update the default or all kernels.

Available keys:
* `path` - kernel path
* `index` - kernel index
* `title` - kernel title
* `initrd` - kernel initrd image

Available strings:
* `DEFAULT` - to update the default entry
* `ALL` - to update all of the entries

2. `options` - with this, specify settings to update
2. `state` - state of the kernel.

Available values: `present`, `absent`

Default: `present`

3. `options` - with this, specify settings to update

* `name` - The name of the setting. `name` is omitted when using `replaced`.
* `value` - The value for the setting. You must omit `value` if the setting has no value, e.g. `quiet`.
* `state` - `present` (default) or `absent`. The value `absent` means to remove a setting with `name` name - name must be provided.
* `previous` - Optional - the only value is `replaced` - this is used to specify that the previous settings should be replaced with the given settings.
* `copy_default` - Optional - when you create a kernel, you can specify `copy_default: true` to copy the default arguments to the created kernel

Example:

```yaml
bootloader_settings:
- kernel:
kernel_path: /boot/vmlinuz-0-rescue-1
options:
- name: console
value: tty0
state: present
- previous: replaced
- kernel:
kernel_index: [1, 2, 3]
options:
- name: print-fatal-signals
value: 1
- kernel:
kernel_title: Red Hat Enterprise Linux (4.1.1.1.el8.x86_64) 8
options:
- name: no_timer_check
- kernel:
kernel_path: /boot/vmlinuz-0-rescue-1
options:
- name: console
value: tty0
- name: print-fatal-signals
value: 1
- name: no_timer_check
state: present
- previous: replaced
- kernel: ALL
options:
- name: debug
state: present
- kernel: DEFAULT
options:
- name: quiet
state: present
```
For an example, see [Example Playbook](#example-playbook).

Default: `{}`

Expand Down Expand Up @@ -195,36 +174,59 @@ For example:
- hosts: all
vars:
bootloader_settings:
# Update an existing kernel using path and replacing previous settings
- kernel:
kernel_path: /boot/vmlinuz-0-rescue-1
path: /boot/vmlinuz-6.5.7-100.fc37.x86_64
options:
- name: console
value: tty0
state: present
- previous: replaced
# Update an existing kernel using index
- kernel:
kernel_index: [1, 2, 3]
index: 1
options:
- name: print-fatal-signals
value: 1
# Update an existing kernel using title
- kernel:
kernel_title: Red Hat Enterprise Linux (4.1.1.1.el8.x86_64) 8
title: Red Hat Enterprise Linux (4.1.1.1.el8.x86_64) 8
options:
- name: no_timer_check
state: present
# Add a kernel with arguments
- kernel:
kernel_path: /boot/vmlinuz-0-rescue-1
path: /boot/vmlinuz-6.5.7-100.fc37.x86_64
initrd: /boot/initramfs-6.5.7-100.fc37.x86_64.img
title: My kernel
options:
- name: console
value: tty0
- name: print-fatal-signals
value: 1
- name: no_timer_check
state: present
- previous: replaced
state: present
# Add a kernel with arguments and copying default arguments
- kernel:
path: /boot/vmlinuz-6.5.7-100.fc37.x86_64
initrd: /boot/initramfs-6.5.7-100.fc37.x86_64.img
title: My kernel
options:
- name: console
value: tty0
- copy_default: true
state: present
# Remove a kernel
- kernel:
title: My kernel
state: absent
# Update all kernels
- kernel: ALL
options:
- name: debug
state: present
# Update the default kernel
- kernel: DEFAULT
options:
- name: quiet
Expand Down
4 changes: 0 additions & 4 deletions handlers/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@
{{ __bootloader_default_grub }}
cat {{ __bootloader_default_grub }}
changed_when: true
when: >-
(ansible_distribution in ['CentOS', 'RedHat'] and
ansible_facts.distribution_major_version is version('7', '=')) or
ansible_distribution == 'Fedora'

- name: Rebuild grub config
command: grub2-mkconfig -o {{ __bootloader_grub_conf }}
Expand Down
6 changes: 3 additions & 3 deletions library/bootloader_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,17 @@


def get_facts(kernels_info, default_kernel):
"""Get kernel facts"""
kernels_info_lines = kernels_info.strip().split("\n")
kernels = []
index_count = 0

for line in kernels_info_lines:
index = re.search(r"index=(\d+)", line)
if index:
is_default = False
is_default = index.group(1) == default_kernel.strip()
index_count += 1
kernels.append({})
if index.group(1) == default_kernel.strip():
is_default = True
search = re.search(r"(.*?)=(.*)", line)
if search:
key = search.group(1).strip('"')
Expand Down
Loading

0 comments on commit 97ef015

Please sign in to comment.