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 a8bb075ccbc..a797f008c7d 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 156e3681906..5b90d616da7 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,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 diff --git a/linux_os/guide/services/ntp/service_timesyncd_configured/tests/common.sh b/linux_os/guide/services/ntp/service_timesyncd_configured/tests/common.sh index 01d815b5e93..d25072eef30 100644 --- a/linux_os/guide/services/ntp/service_timesyncd_configured/tests/common.sh +++ b/linux_os/guide/services/ntp/service_timesyncd_configured/tests/common.sh @@ -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 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 1e9233b82a9..a45fe535e38 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 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" diff --git a/linux_os/guide/services/ntp/service_timesyncd_root_distance_configured/tests/common.sh b/linux_os/guide/services/ntp/service_timesyncd_root_distance_configured/tests/common.sh index 01d815b5e93..4724bd63b8a 100644 --- a/linux_os/guide/services/ntp/service_timesyncd_root_distance_configured/tests/common.sh +++ b/linux_os/guide/services/ntp/service_timesyncd_root_distance_configured/tests/common.sh @@ -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