Skip to content

Commit fc1e897

Browse files
authored
Merge pull request #14638 from ggbecker/fix-chrony-d-remediation
Fix chronyd_or_ntpd_set_maxpoll bash remediation when /etc/chrony.d is missing
2 parents 7389dd2 + e5bbfcc commit fc1e897

File tree

4 files changed

+50
-9
lines changed

4 files changed

+50
-9
lines changed

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
# packages = chrony
3+
# variables = var_time_service_set_maxpoll=16
4+
# platform = multi_platform_rhel,multi_platform_fedora,multi_platform_ol,multi_platform_sle
5+
6+
{{{ bash_package_remove("ntp") }}}
7+
8+
# Remove the /etc/chrony.d directory to simulate systems where it doesn't exist
9+
# (e.g., ppc64le systems with chrony-dhcp in Testing Farm)
10+
rm -rf {{{ chrony_d_path }}}
11+
12+
# Configure maxpoll correctly in the main chrony.conf file
13+
sed -i "/^\(server\|pool\).*/d" {{{ chrony_conf_path }}}
14+
echo "pool pool.ntp.org iburst maxpoll 16" >> {{{ chrony_conf_path }}}
15+
echo "server time.nist.gov maxpoll 16" >> {{{ chrony_conf_path }}}
16+
17+
systemctl enable chronyd.service
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
# packages = chrony
3+
# variables = var_time_service_set_maxpoll=16
4+
# platform = multi_platform_rhel,multi_platform_fedora,multi_platform_ol,multi_platform_sle
5+
# remediation = bash,ansible
6+
7+
{{{ bash_package_remove("ntp") }}}
8+
9+
# Remove the /etc/chrony.d directory to simulate systems where it doesn't exist
10+
# (e.g., ppc64le systems with chrony-dhcp in Testing Farm)
11+
rm -rf {{{ chrony_d_path }}}
12+
13+
# Configure maxpoll incorrectly in the main chrony.conf file
14+
sed -i "/^\(server\|pool\).*/d" {{{ chrony_conf_path }}}
15+
echo "pool pool.ntp.org iburst maxpoll 18" >> {{{ chrony_conf_path }}}
16+
echo "server time.nist.gov maxpoll 20" >> {{{ chrony_conf_path }}}
17+
18+
systemctl enable chronyd.service

0 commit comments

Comments
 (0)