diff --git a/linux_os/guide/services/ntp/service_timesyncd_configured/ansible/shared.yml b/linux_os/guide/services/ntp/service_timesyncd_configured/ansible/shared.yml index a8bb075ccbc3..a797f008c7dd 100644 --- a/linux_os/guide/services/ntp/service_timesyncd_configured/ansible/shared.yml +++ b/linux_os/guide/services/ntp/service_timesyncd_configured/ansible/shared.yml @@ -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 diff --git a/linux_os/guide/services/ntp/service_timesyncd_configured/bash/shared.sh b/linux_os/guide/services/ntp/service_timesyncd_configured/bash/shared.sh index 156e36819065..d2f23cc2c08f 100644 --- a/linux_os/guide/services/ntp/service_timesyncd_configured/bash/shared.sh +++ b/linux_os/guide/services/ntp/service_timesyncd_configured/bash/shared.sh @@ -5,22 +5,23 @@ # 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 - sed -i 's/^NTP/#&/g' "$current_cfg" - sed -i 's/^FallbackNTP/#&/g' "$current_cfg" -done +if [ ${#current_cfg_arr[@]} -ne 0 ]; then + for current_cfg in "${current_cfg_arr[@]}" + do + sed -i 's/^NTP/#&/g' "$current_cfg" + sed -i 's/^FallbackNTP/#&/g' "$current_cfg" + done +fi # Set primary fallback NTP servers in drop-in configuration echo "NTP=$preferred_ntp_servers" >> "$config_file" echo "FallbackNTP=$fallback_ntp_servers" >> "$config_file" diff --git a/linux_os/guide/services/ntp/service_timesyncd_root_distance_configured/bash/shared.sh b/linux_os/guide/services/ntp/service_timesyncd_root_distance_configured/bash/shared.sh index 1e9233b82a95..81c9a1945bcf 100644 --- a/linux_os/guide/services/ntp/service_timesyncd_root_distance_configured/bash/shared.sh +++ b/linux_os/guide/services/ntp/service_timesyncd_root_distance_configured/bash/shared.sh @@ -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 FallbackNTP 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"