Skip to content

Commit 6f77a83

Browse files
committed
Enable kpatch support for updates
This change enables kpatch-patch support, allowing in-place kernel patching for security and bug fixes, provided `kpatch-patch-KERNEL_VERSION` package exists. For more information about kpatch: https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/9/html/managing_monitoring_and_updating_the_kernel/applying-patches-with-kernel-live-patching_managing-monitoring-and-updating-the-kernel This PR also corrects a potential issue related to the exclide list applied to the package update: if a user were to pass the `edpm_update_exclude_packages` parameter, the subsequent override wouldn't be applied, meaning the `openvswitch` package wouldn't be excluded in the end. Using an "internal var" such as the `_exclude_packages` in order to inject our own content in addition to whatever the user may pass ensures everything is working as expected. Fixes: https://issues.redhat.com/browse/OSPRH-11274
1 parent ccbccb1 commit 6f77a83

File tree

7 files changed

+146
-4
lines changed

7 files changed

+146
-4
lines changed

roles/edpm_update/defaults/main.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717

1818
# All variables intended for modification should be placed in this file.
1919

20+
# Toggle to enable/disable kpatch usage
21+
edpm_update_enable_kpatch: false
22+
2023
# Toggle to enable/disable packages updates
2124
edpm_update_enable_packages_update: true
2225

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
---
2+
# Copyright 2024 Red Hat, Inc.
3+
# All Rights Reserved.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
6+
# not use this file except in compliance with the License. You may obtain
7+
# a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14+
# License for the specific language governing permissions and limitations
15+
# under the License.
16+
17+
18+
- name: Converge
19+
hosts: all
20+
gather_facts: false
21+
tasks:
22+
- name: "Call edpm_update role"
23+
ansible.builtin.include_role:
24+
name: osp.edpm.edpm_update
25+
vars:
26+
edpm_update_enable_containers_update: false
27+
edpm_service_types: []
28+
edpm_update_enable_kpatch: true
29+
30+
# We have to run the verifications in this play to
31+
# ensure we have access to the internally changed
32+
# facts.
33+
- name: Conduct some verifications
34+
block:
35+
- name: Ensure kernel related packages are excluded
36+
ansible.builtin.assert:
37+
that:
38+
- _exclude_packages is defined
39+
- "'kernel' in _exclude_packages"
40+
- "'kernel-core' in _exclude_packages"
41+
42+
- name: Gather all installed packages
43+
ansible.builtin.package_facts:
44+
45+
- name: Check service status if we have kpatch-patch installed
46+
when:
47+
- ansible_facts.packages["kpatch-patch"] is defined
48+
block:
49+
- name: Gather services
50+
ansible.builtin.service_facts:
51+
52+
- name: Ensure kpatch.service is running
53+
ansible.builtin.assert:
54+
that:
55+
- ansible_facts.services['kpatch.service'] is defined
56+
- ansible_facts.services['kpatch.service'].state == 'running'
57+
- ansible_facts.services['kpatch.service'].status == 'enabled'
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
dependency:
3+
name: galaxy
4+
options:
5+
role-file: collections.yml
6+
driver:
7+
name: delegated
8+
options:
9+
managed: false
10+
ansible_connection_options:
11+
ansible_connection: local
12+
platforms:
13+
- name: edpm-0.localdomain
14+
groups:
15+
- compute
16+
provisioner:
17+
log: true
18+
name: ansible
19+
20+
scenario:
21+
test_sequence:
22+
- prepare
23+
- converge
24+
- cleanup
25+
- destroy
26+
verifier:
27+
name: ansible
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
# Copyright 2024 Red Hat, Inc.
3+
# All Rights Reserved.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
6+
# not use this file except in compliance with the License. You may obtain
7+
# a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14+
# License for the specific language governing permissions and limitations
15+
# under the License.
16+
17+
- name: Run prepare playbook
18+
ansible.builtin.import_playbook: ../default/prepare.yml

roles/edpm_update/tasks/kpatch.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
- name: Ensure we know about kernel version
3+
when:
4+
- ansible_facts['kernel'] is undefined
5+
ansible.builtin.setup:
6+
gather_subset:
7+
- '!all,!min'
8+
- 'kernel'
9+
10+
- name: Ensure kpatch package is installed
11+
become: true
12+
ansible.builtin.package:
13+
name: kpatch
14+
state: present
15+
16+
- name: Install kpatch-patch if available # noqa: package-latest
17+
failed_when: false
18+
become: true
19+
ansible.builtin.package:
20+
name: "kpatch-patch = {{ ansible_facts['kernel'] }}"
21+
state: latest
22+
23+
- name: Ensure further update stages will not update kernel
24+
vars:
25+
_kernel:
26+
- kernel
27+
- kernel-core
28+
ansible.builtin.set_fact:
29+
_exclude_packages: "{{ edpm_update_exclude_packages + _kernel }}"

roles/edpm_update/tasks/main.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717

1818
# "edpm_update" will search for and load any operating system variable file
1919

20+
- name: Apply kernel patch via kpatch
21+
ansible.builtin.include_tasks: kpatch.yml
22+
when: edpm_update_enable_kpatch
23+
2024
- name: Update packages
2125
ansible.builtin.include_tasks: packages.yml
2226
when: edpm_update_enable_packages_update

roles/edpm_update/tasks/packages.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,13 @@
99

1010
- name: Ensure openvswitch is excluded from bulk update
1111
ansible.builtin.set_fact:
12-
edpm_update_exclude_packages: "{{ edpm_update_exclude_packages + ['openvswitch'] }}"
13-
when:
14-
"'openvswitch' not in edpm_update_exclude_packages"
12+
_exclude_packages: >-
13+
{{
14+
_exclude_packages | default([]) +
15+
edpm_update_exclude_packages +
16+
['openvswitch'] |
17+
ansible.builtin.unique
18+
}}
1519
tags:
1620
- edpm_update
1721

@@ -21,6 +25,6 @@
2125
name: "*"
2226
state: latest
2327
update_cache: true
24-
exclude: "{{ edpm_update_exclude_packages }}"
28+
exclude: "{{ _exclude_packages }}"
2529
tags:
2630
- edpm_update

0 commit comments

Comments
 (0)