Skip to content

Commit 950adf2

Browse files
authored
Merge pull request #1083 from berndfinger/issue-1081-grub2-mkconfig-command-line-args-rhel93
sap_hana_preconfigure: Replace grub2-mkconfig for RHEL by grubby from RHEL 8 onward
2 parents 43d159f + bf27c2c commit 950adf2

16 files changed

+290
-357
lines changed

roles/sap_hana_preconfigure/handlers/main.yml

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,20 +72,13 @@
7272
- __sap_hana_preconfigure_register_stat_sys_firmware_efi.stat.exists
7373
- sap_hana_preconfigure_run_grub2_mkconfig | d(true)
7474

75-
- name: "Run grubby for enabling TSX"
75+
- name: "Run grubby for configuring kernel command line entries for SAP"
7676
ansible.builtin.command:
77-
cmd: grubby --args="tsx=on" --update-kernel=ALL
77+
cmd: "{{ __sap_hana_preconfigure_fact_grubby_command }}"
7878
changed_when: true
7979
listen: __sap_hana_preconfigure_grubby_update_handler
8080
notify: __sap_hana_preconfigure_reboot_handler
8181

82-
- name: "Run grubby for setting THP to '{{ __sap_hana_preconfigure_fact_thp }}'"
83-
ansible.builtin.command:
84-
cmd: grubby --args="transparent_hugepage={{ __sap_hana_preconfigure_fact_thp }}" --update-kernel=ALL
85-
changed_when: true
86-
listen: __sap_hana_preconfigure_grubby_thp_handler
87-
notify: __sap_hana_preconfigure_reboot_handler
88-
8982
# END - GRUB section
9083

9184

roles/sap_hana_preconfigure/tasks/RedHat/configuration.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@
88
ansible.builtin.debug:
99
var: __sap_hana_preconfigure_sapnotes_versions | difference([''])
1010

11+
- name: Configure - Initialize vars for boot command line updates
12+
ansible.builtin.set_fact:
13+
__sap_hana_preconfigure_boot_command_line_args_final: []
14+
__sap_hana_preconfigure_fact_missing_kernel_args: []
15+
__sap_hana_preconfigure_kernel_args_to_be_updated: []
16+
__sap_hana_preconfigure_fact_kernel_args_to_be_set: []
17+
1118
- name: Configure - Set directory variables for setting SELinux file contexts
1219
ansible.builtin.set_fact:
1320
sap_hana_preconfigure_fact_targets_setypes: "{{ sap_hana_preconfigure_fact_targets_setypes | d([]) +
@@ -43,3 +50,12 @@
4350
with_items: "{{ __sap_hana_preconfigure_sapnotes_versions | difference(['']) }}"
4451
loop_control:
4552
loop_var: sap_note_line_item
53+
54+
- name: Configure - Initiate GRUB update if necessary
55+
ansible.builtin.include_tasks:
56+
file: "generic/set-boot-kernel-args.yml"
57+
apply:
58+
tags:
59+
- grubconfig
60+
when: __sap_hana_preconfigure_boot_command_line_args_final | length > 0
61+
tags: grubconfig

roles/sap_hana_preconfigure/tasks/RedHat/generic/assert-thp.yml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
__sap_hana_preconfigure_fact_thp: 'never'
2929
when:
3030
- sap_hana_preconfigure_thp is undefined or sap_hana_preconfigure_thp | length == 0
31-
- ansible_distribution == 'RedHat'
3231
- ansible_distribution_major_version == '7' or
3332
ansible_distribution_major_version == '8' or
3433
ansible_distribution_version == '9.0' or
@@ -39,10 +38,9 @@
3938
__sap_hana_preconfigure_fact_thp: 'madvise'
4039
when:
4140
- sap_hana_preconfigure_thp is undefined or sap_hana_preconfigure_thp | length == 0
42-
- ansible_distribution == 'RedHat'
43-
- (ansible_distribution_major_version == '9' and
44-
__sap_hana_preconfigure_fact_ansible_distribution_minor_version | int >= 2) or
45-
ansible_distribution_major_version == '10'
41+
- ansible_distribution_major_version | int >= 10 or
42+
(ansible_distribution_major_version == '9' and
43+
__sap_hana_preconfigure_fact_ansible_distribution_minor_version | int >= 2)
4644

4745
- name: Set fact for THP if 'sap_hana_preconfigure_thp' is defined
4846
ansible.builtin.set_fact:

roles/sap_hana_preconfigure/tasks/RedHat/generic/assert-tsx.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
when:
66
- ansible_architecture == 'x86_64'
77
- ansible_distribution == 'RedHat'
8-
- (ansible_distribution_major_version >= '9') or
8+
- ansible_distribution_major_version | int >= 9 or
99
(ansible_distribution_major_version == '8' and
1010
__sap_hana_preconfigure_fact_ansible_distribution_minor_version | int >= 3)
1111
block:

roles/sap_hana_preconfigure/tasks/RedHat/generic/configure-c-states-for-lower-latency.yml

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,13 @@
22
---
33

44
# can be configured by tuned profile sap-hana, entry "force_latency=70"
5-
- name: Configure C-States for lower latency
6-
ansible.builtin.lineinfile:
7-
path: /etc/default/grub
8-
backup: yes
9-
backrefs: yes
10-
state: present
11-
regexp: '^(GRUB_CMDLINE_LINUX=(?!.* {{ line_item }}).*). *$'
12-
line: "\\1 {{ line_item }}\""
13-
with_items:
14-
- "processor.max_cstate=1"
15-
- "intel_idle.max_cstate=1"
16-
notify: __sap_hana_preconfigure_regenerate_grub2_conf_handler
17-
when: ansible_architecture == 'x86_64' and
18-
(not sap_hana_preconfigure_use_tuned or
19-
sap_hana_preconfigure_modify_grub_cmdline_linux)
20-
tags: grubconfig
5+
- name: Add boot command line args for configuring C-States for lower latency
6+
ansible.builtin.set_fact:
7+
__sap_hana_preconfigure_boot_command_line_args_final: >-
8+
{{ __sap_hana_preconfigure_boot_command_line_args_final + [__sap_hana_preconfigure_kernel_arg_line_item] }}
9+
loop: "{{ __sap_hana_preconfigure_boot_command_line_args['c-states']['args'] }}"
2110
loop_control:
22-
loop_var: line_item
11+
loop_var: __sap_hana_preconfigure_kernel_arg_line_item
12+
when:
13+
- __sap_hana_preconfigure_boot_command_line_args['c-states']['arch'] is defined
14+
- ansible_architecture in __sap_hana_preconfigure_boot_command_line_args['c-states']['arch']
Lines changed: 39 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,50 @@
11
# SPDX-License-Identifier: Apache-2.0
22
---
33

4-
- name: Get boot command line
5-
ansible.builtin.slurp:
6-
src: /proc/cmdline
7-
register: __sap_hana_preconfigure_register_proc_cmdline_thp
8-
9-
- name: Set fact for THP, RHEL up to RHEL 9.1
4+
- name: Set fact for THP if 'sap_hana_preconfigure_thp' is defined
105
ansible.builtin.set_fact:
11-
__sap_hana_preconfigure_fact_thp: 'never'
6+
__sap_hana_preconfigure_fact_thp: "{{ sap_hana_preconfigure_thp }}"
127
when:
13-
- sap_hana_preconfigure_thp is undefined or sap_hana_preconfigure_thp | length == 0
14-
- ansible_distribution == 'RedHat'
15-
- ansible_distribution_major_version == '7' or
16-
ansible_distribution_major_version == '8' or
17-
ansible_distribution_version == '9.0' or
18-
ansible_distribution_version == '9.1'
8+
- sap_hana_preconfigure_thp is defined
9+
- sap_hana_preconfigure_thp | length > 0
1910

20-
- name: Set fact for THP, RHEL 9.2 and later
11+
- name: Set fact for THP if 'sap_hana_preconfigure_thp' is undefined
2112
ansible.builtin.set_fact:
22-
__sap_hana_preconfigure_fact_thp: 'madvise'
13+
__sap_hana_preconfigure_fact_thp: "{{ __sap_hana_preconfigure_boot_command_line_args['thp']['args'][0].split('=')[1] }}"
2314
when:
15+
- __sap_hana_preconfigure_boot_command_line_args['thp']['arch'] is defined
2416
- sap_hana_preconfigure_thp is undefined or sap_hana_preconfigure_thp | length == 0
25-
- ansible_distribution == 'RedHat'
26-
- (ansible_distribution_major_version == '9' and
27-
__sap_hana_preconfigure_fact_ansible_distribution_minor_version | int >= 2) or
28-
ansible_distribution_major_version == '10'
2917

30-
- name: Set fact for THP if 'sap_hana_preconfigure_thp' is defined
31-
ansible.builtin.set_fact:
32-
__sap_hana_preconfigure_fact_thp: "{{ sap_hana_preconfigure_thp }}"
33-
when:
34-
- sap_hana_preconfigure_thp is defined and sap_hana_preconfigure_thp
35-
36-
- name: Set THP to '{{ __sap_hana_preconfigure_fact_thp }}' at boot time
37-
ansible.builtin.command: /bin/true
38-
notify: __sap_hana_preconfigure_grubby_thp_handler
39-
changed_when: true
40-
when: not ( __sap_hana_preconfigure_register_proc_cmdline_thp['content'] | b64decode | regex_findall('transparent_hugepage=' + __sap_hana_preconfigure_fact_thp) )
41-
tags: grubconfig
42-
43-
- name: Configure - Get initial status of THP
44-
ansible.builtin.command: cat /sys/kernel/mm/transparent_hugepage/enabled
45-
register: __sap_hana_preconfigure_register_thp_status_before
46-
changed_when: false
47-
48-
- name: Set THP to '{{ __sap_hana_preconfigure_fact_thp }}' on the running system
49-
ansible.builtin.shell: echo '{{ __sap_hana_preconfigure_fact_thp }}' > /sys/kernel/mm/transparent_hugepage/enabled
50-
changed_when: true
18+
- name: Add boot command line args for configuring THP if applicable
5119
when:
52-
- not ansible_check_mode
53-
- __sap_hana_preconfigure_register_thp_status_before.stdout.split('[')[1].split(']')[0] != __sap_hana_preconfigure_fact_thp
54-
55-
- name: Configure - Get the status of THP
56-
ansible.builtin.command: cat /sys/kernel/mm/transparent_hugepage/enabled
57-
register: __sap_hana_preconfigure_register_thp_status
58-
ignore_errors: true
59-
changed_when: false
60-
61-
- name: Display the status of THP
62-
ansible.builtin.debug:
63-
var: __sap_hana_preconfigure_register_thp_status.stdout_lines, __sap_hana_preconfigure_register_thp_status.stderr_lines
20+
- (sap_hana_preconfigure_thp is defined and sap_hana_preconfigure_thp | length > 0)
21+
or __sap_hana_preconfigure_boot_command_line_args['thp']['arch'] is defined
22+
block:
23+
24+
- name: Add boot command line args for configuring THP
25+
ansible.builtin.set_fact:
26+
__sap_hana_preconfigure_boot_command_line_args_final: >-
27+
{{ __sap_hana_preconfigure_boot_command_line_args_final
28+
+ ['transparent_hugepage=' + __sap_hana_preconfigure_fact_thp] }}
29+
30+
- name: Configure - Get initial status of THP
31+
ansible.builtin.command: cat /sys/kernel/mm/transparent_hugepage/enabled
32+
register: __sap_hana_preconfigure_register_thp_status_before
33+
changed_when: false
34+
35+
- name: Set THP to '{{ __sap_hana_preconfigure_fact_thp }}' on the running system
36+
ansible.builtin.shell: echo '{{ __sap_hana_preconfigure_fact_thp }}' > /sys/kernel/mm/transparent_hugepage/enabled
37+
changed_when: true
38+
when:
39+
- not ansible_check_mode
40+
- __sap_hana_preconfigure_register_thp_status_before.stdout.split('[')[1].split(']')[0] != __sap_hana_preconfigure_fact_thp
41+
42+
- name: Configure - Get the status of THP
43+
ansible.builtin.command: cat /sys/kernel/mm/transparent_hugepage/enabled
44+
register: __sap_hana_preconfigure_register_thp_status
45+
ignore_errors: true
46+
changed_when: false
47+
48+
- name: Display the status of THP
49+
ansible.builtin.debug:
50+
var: __sap_hana_preconfigure_register_thp_status.stdout_lines, __sap_hana_preconfigure_register_thp_status.stderr_lines
Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,13 @@
11
# SPDX-License-Identifier: Apache-2.0
22
---
33

4-
- name: Get boot command line
5-
ansible.builtin.slurp:
6-
src: /proc/cmdline
7-
register: __sap_hana_preconfigure_register_proc_cmdline
8-
9-
- name: Enable TSX at boot time
10-
ansible.builtin.command: /bin/true
11-
notify: __sap_hana_preconfigure_grubby_update_handler
12-
changed_when: true
4+
- name: Add boot command line args for configuring TSX
5+
ansible.builtin.set_fact:
6+
__sap_hana_preconfigure_boot_command_line_args_final: >-
7+
{{ __sap_hana_preconfigure_boot_command_line_args_final + [__sap_hana_preconfigure_kernel_arg_line_item] }}
8+
loop: "{{ __sap_hana_preconfigure_boot_command_line_args['tsx']['args'] }}"
9+
loop_control:
10+
loop_var: __sap_hana_preconfigure_kernel_arg_line_item
1311
when:
14-
- ansible_architecture == 'x86_64'
15-
- ansible_distribution == 'RedHat'
16-
- (ansible_distribution_major_version >= '9') or
17-
(ansible_distribution_major_version == '8' and
18-
__sap_hana_preconfigure_fact_ansible_distribution_minor_version | int >= 3)
19-
- not ( __sap_hana_preconfigure_register_proc_cmdline['content'] | b64decode | regex_findall('tsx=on') )
20-
tags: grubconfig
12+
- __sap_hana_preconfigure_boot_command_line_args['tsx']['arch'] is defined
13+
- ansible_architecture in __sap_hana_preconfigure_boot_command_line_args['tsx']['arch']
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
---
3+
4+
- name: Get all kernel command line args for all grub entries
5+
ansible.builtin.shell: set -o pipefail && grubby --info=ALL
6+
register: __sap_hana_preconfigure_register_grubby_info_all
7+
check_mode: false
8+
changed_when: false
9+
10+
- name: Validate the grubby output
11+
ansible.builtin.fail:
12+
msg: "FAIL: No grub or grub args entries found!"
13+
when:
14+
- __sap_hana_preconfigure_register_grubby_info_all.stdout == ""
15+
- "'args=' not in __sap_hana_preconfigure_register_grubby_info_all.stdout"
16+
17+
- name: Store all lines containing the kernel arguments
18+
ansible.builtin.set_fact:
19+
__sap_hana_preconfigure_fact_all_kernel_args_lines: >-
20+
{{
21+
__sap_hana_preconfigure_register_grubby_info_all.stdout |
22+
regex_findall('args="([^"]*)"')
23+
}}
24+
25+
# We first identify kernel args which are missing in at least one grub entry
26+
- name: Identify missing kernel args
27+
ansible.builtin.set_fact:
28+
__sap_hana_preconfigure_fact_missing_kernel_args: >-
29+
{{
30+
__sap_hana_preconfigure_fact_missing_kernel_args + [__sap_hana_preconfigure_missing_kernel_arg_item]
31+
}}
32+
loop: "{{ __sap_hana_preconfigure_boot_command_line_args_final }}"
33+
loop_control:
34+
loop_var: __sap_hana_preconfigure_missing_kernel_arg_item
35+
when: >-
36+
__sap_hana_preconfigure_fact_all_kernel_args_lines |
37+
select('search', __sap_hana_preconfigure_missing_kernel_arg_item.split('=')[0] + '=') |
38+
list | length < __sap_hana_preconfigure_fact_all_kernel_args_lines | length
39+
40+
# We then identify kernel args which are
41+
# - either not set correctly in all grub entries, or
42+
# - set differently (meaning that the arg/value combination for a desired arg occurs more than once)
43+
- name: Identify kernel args to be updated
44+
ansible.builtin.set_fact:
45+
__sap_hana_preconfigure_kernel_args_to_be_updated: >-
46+
{{
47+
__sap_hana_preconfigure_kernel_args_to_be_updated + [__sap_hana_preconfigure_kernel_arg_to_be_updated_item]
48+
}}
49+
loop: "{{ __sap_hana_preconfigure_boot_command_line_args_final }}"
50+
loop_control:
51+
loop_var: __sap_hana_preconfigure_kernel_arg_to_be_updated_item
52+
when: >-
53+
(
54+
__sap_hana_preconfigure_kernel_arg_to_be_updated_item not in
55+
__sap_hana_preconfigure_fact_all_kernel_args_lines
56+
| join(' ') | split | unique
57+
) or (
58+
__sap_hana_preconfigure_fact_all_kernel_args_lines
59+
| join(' ') | split | unique
60+
| select('search', __sap_hana_preconfigure_kernel_arg_to_be_updated_item.split('=')[0]) | list | length > 1
61+
)
62+
63+
- name: Display grub and kernel args information
64+
ansible.builtin.debug:
65+
msg: |
66+
Number of grub entries: {{ __sap_hana_preconfigure_fact_all_kernel_args_lines | length }}
67+
Required arguments: {{ __sap_hana_preconfigure_boot_command_line_args_final }}
68+
Missing kernel args: {{ __sap_hana_preconfigure_fact_missing_kernel_args }}
69+
Kernel args to be updated: {{ __sap_hana_preconfigure_kernel_args_to_be_updated }}
70+
71+
- name: Set fact for all required kernel arg updates
72+
ansible.builtin.set_fact:
73+
__sap_hana_preconfigure_fact_kernel_args_to_be_set: >-
74+
{{ (__sap_hana_preconfigure_fact_missing_kernel_args
75+
+ __sap_hana_preconfigure_kernel_args_to_be_updated) | unique
76+
}}
77+
78+
- name: Display kernel args to be set
79+
ansible.builtin.debug:
80+
msg: "Kernel args to be set: '{{ __sap_hana_preconfigure_fact_kernel_args_to_be_set }}'"
81+
82+
- name: Construct the grubby command for configuring the kernel command line entries
83+
ansible.builtin.set_fact:
84+
__sap_hana_preconfigure_fact_grubby_command: >-
85+
grubby --args="{{ __sap_hana_preconfigure_fact_kernel_args_to_be_set | join(' ') | trim }}" --update-kernel=ALL
86+
when:
87+
- __sap_hana_preconfigure_fact_kernel_args_to_be_set | length > 0
88+
89+
- name: Display the grubby command to be run
90+
ansible.builtin.debug:
91+
msg: "Grubby command: '{{ __sap_hana_preconfigure_fact_grubby_command }}'"
92+
when:
93+
- __sap_hana_preconfigure_fact_kernel_args_to_be_set | length > 0
94+
95+
# Reason for noqa: The command does not change anything but if we set 'changed_when: true',
96+
# the handler will not be notified.
97+
- name: Trigger kernel command line update if necessary # noqa no-changed-when
98+
ansible.builtin.command:
99+
cmd: /bin/true
100+
notify: __sap_hana_preconfigure_grubby_update_handler
101+
when:
102+
- __sap_hana_preconfigure_fact_kernel_args_to_be_set | length > 0

0 commit comments

Comments
 (0)