Skip to content

Commit 3f15126

Browse files
committed
Fix chronyd_or_ntpd_set_maxpoll remediation when /etc/chrony.d is missing
Both bash and Ansible remediation scripts failed when /etc/chrony.d directory doesn't exist, which happens on systems using chrony-dhcp (e.g., ppc64le systems in Testing Farm). Bash remediation: - Add directory existence check before running find - Remove product-specific branching and unify code path - Initialize empty array if directory is missing Ansible remediation: - Add stat task to check directory existence before find - Only run find when directory exists and is a directory - Use 'default([])' for safe variable handling - Check variable is defined before accessing .matched Fixes #14541
1 parent c4ec598 commit 3f15126

2 files changed

Lines changed: 15 additions & 9 deletions

File tree

linux_os/guide/services/ntp/chronyd_or_ntpd_set_maxpoll/ansible/shared.yml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,25 +48,31 @@
4848
replace: '\1 maxpoll {{ var_time_service_set_maxpoll }}\n'
4949
when: chrony_conf_exist_result.stat.exists
5050

51+
- name: "{{{ rule_title }}} - Check That {{{ chrony_d_path }}} Exist"
52+
ansible.builtin.stat:
53+
path: "{{{ chrony_d_path }}}"
54+
register: chrony_d_path_exists
55+
5156
- name: "{{{ rule_title }}} - Get Conf Files from {{{ chrony_d_path }}}"
5257
ansible.builtin.find:
5358
path: "{{{ chrony_d_path }}}"
5459
patterns: '*.conf'
5560
file_type: file
5661
register: chrony_d_conf_files
62+
when: chrony_d_path_exists.stat.exists and chrony_d_path_exists.stat.isdir
5763

5864
- name: "{{{ rule_title }}} - Update the maxpoll Values in {{{ chrony_d_path }}}"
5965
ansible.builtin.replace:
6066
path: "{{ item.path }}"
6167
regexp: '^((?:server|pool|peer).*maxpoll)[ ]+[0-9,-]+(.*)$'
6268
replace: '\1 {{ var_time_service_set_maxpoll }}\2'
63-
loop: '{{ chrony_d_conf_files.files }}'
64-
when: chrony_d_conf_files.matched
69+
loop: '{{ chrony_d_conf_files.files | default([]) }}'
70+
when: chrony_d_conf_files is defined and chrony_d_conf_files.matched
6571

6672
- name: "{{{ rule_title }}} - Set the maxpoll Values in {{{ chrony_d_path }}}"
6773
ansible.builtin.replace:
6874
path: "{{ item.path }}"
6975
regexp: '(^(?:server|pool|peer)\s+((?!maxpoll).)*)$'
7076
replace: '\1 maxpoll {{ var_time_service_set_maxpoll }}\n'
71-
loop: '{{ chrony_d_conf_files.files }}'
72-
when: chrony_d_conf_files.matched
77+
loop: '{{ chrony_d_conf_files.files | default([]) }}'
78+
when: chrony_d_conf_files is defined and chrony_d_conf_files.matched

linux_os/guide/services/ntp/chronyd_or_ntpd_set_maxpoll/bash/shared.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ pof="/usr/sbin/pidof"
1212
CONFIG_FILES="/etc/ntp.conf"
1313
$pof ntpd || {
1414
CHRONY_D_PATH={{{ chrony_d_path }}}
15-
{{% if 'slmicro' in product %}}
16-
mapfile -t CONFIG_FILES < <(find ${CHRONY_D_PATH} -type f -name '*.conf')
17-
{{% else %}}
18-
mapfile -t CONFIG_FILES < <(find ${CHRONY_D_PATH}.* -type f -name '*.conf')
19-
{{% endif %}}
15+
if [ -d "${CHRONY_D_PATH}" ]; then
16+
mapfile -t CONFIG_FILES < <(find ${CHRONY_D_PATH} -type f -name '*.conf')
17+
else
18+
CONFIG_FILES=()
19+
fi
2020
CONFIG_FILES+=({{{ chrony_conf_path }}})
2121
}
2222

0 commit comments

Comments
 (0)