Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve stability of timesyncd based remediation #11247

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

- name: {{{ rule_title }}} - Set Fallback NTP Servers
ansible.builtin.set_fact:
fallback_ntp_servers: '{{ var_multiple_time_servers.split(",") | slice(2)| last |
fallback_ntp_servers: '{{ var_multiple_time_servers.split(",") | slice(2)| list | last |
join(",") }}'

- name: {{{ rule_title }}} - Add missing / update wrong records for NTP servers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@
# disruption = low

{{{ bash_instantiate_variables("var_multiple_time_servers") }}}

IFS=',' read -r -a time_servers_array <<< "$var_multiple_time_servers"
preferred_ntp_servers_array=("${time_servers_array[@]:0:2}")
preferred_ntp_servers=$( echo "${preferred_ntp_servers_array[@]}"|sed -e 's/\s\+/,/g' )
fallback_ntp_servers_array=("${time_servers_array[@]:2}")
fallback_ntp_servers=$( echo "${fallback_ntp_servers_array[@]}"|sed -e 's/\s\+/,/g' )

IFS=" " mapfile -t current_cfg_arr < <(ls -1 /etc/systemd/timesyncd.d/* 2>/dev/null)
config_file="/etc/systemd/timesyncd.d/oscap-remedy.conf"
current_cfg_arr=( "/etc/systemd/timesyncd.conf" )
current_cfg_arr+=("$(ls /etc/systemd/timesyncd.d/*)")
current_cfg_arr+=( "/etc/systemd/timesyncd.conf" )
# Comment existing NTP FallbackNTP settings
for current_cfg in "${current_cfg_arr[@]}"
do
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash

mkdir -p /etc/systemd/timesyncd.d/
echo "" > /etc/systemd/timesyncd.conf
echo "" > /etc/systemd/timesyncd.d/oscap-remedy.conf
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
# disruption = low

config_file="/etc/systemd/timesyncd.d/oscap-remedy.conf"
current_cfg_arr=( "/etc/systemd/timesyncd.conf" )
current_cfg_arr+=("$(ls /etc/systemd/timesyncd.d/*)")
# Comment existing NTP RootDistance settings
for current_cfg in "${current_cfg_arr[@]}"
do
sed -i 's/^RootDistanceMax/#&/g' "$current_cfg"
done
IFS=" " mapfile -t current_cfg_arr < <(ls -1 /etc/systemd/timesyncd.d/* 2>/dev/null)
current_cfg_arr+=( "/etc/systemd/timesyncd.conf" )
# Comment existing NTP RootDistanceMax settings
if [ ${#current_cfg_arr[@]} -ne 0 ]; then
for current_cfg in "${current_cfg_arr[@]}"
do
sed -i 's/^RootDistanceMax/#&/g' "$current_cfg"
done
fi
# Set RootDistance in drop-in configuration
echo "RootDistanceMax=1" >> "$config_file"
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash

mkdir -p /etc/systemd/timesyncd.d/
echo "" > /etc/systemd/timesyncd.conf
echo "" > /etc/systemd/timesyncd.d/oscap-remedy.conf
Loading