diff --git a/docs/ntp.md b/docs/ntp.md index efa40b934..4a8dc0419 100644 --- a/docs/ntp.md +++ b/docs/ntp.md @@ -26,6 +26,15 @@ ntp_servers: - "3.your-ntp-server.org iburst" ``` +## Setting the TimeZone + +The timezone can also be set by the `ntp_timezone` , eg: "Etc/UTC","Asia/Shanghai". If not set, the timezone will not change. + +```ShellSession +ntp_enabled: true +ntp_timezone: Etc/UTC +``` + ## Advanced Configure Enable `tinker panic` is useful when running NTP in a VM environment to avoiding clock drift on VMs. It only takes effect when ntp_manage_config is true. diff --git a/roles/kubernetes/preinstall/defaults/main.yml b/roles/kubernetes/preinstall/defaults/main.yml index d1cc42cee..e06485101 100644 --- a/roles/kubernetes/preinstall/defaults/main.yml +++ b/roles/kubernetes/preinstall/defaults/main.yml @@ -100,3 +100,6 @@ ntp_tinker_panic: false # Force sync time immediately after the ntp installed, which is useful in in newly installed system. ntp_force_sync_immediately: false + +# Set the timezone for your server. eg: "Etc/UTC","Etc/GMT-8". If not set, the timezone will not change. +ntp_timezone: "" diff --git a/roles/kubernetes/preinstall/tasks/0081-ntp-configurations.yml b/roles/kubernetes/preinstall/tasks/0081-ntp-configurations.yml index ba4578744..d80d14e5e 100644 --- a/roles/kubernetes/preinstall/tasks/0081-ntp-configurations.yml +++ b/roles/kubernetes/preinstall/tasks/0081-ntp-configurations.yml @@ -63,3 +63,17 @@ name: "{{ ntp_service_name }}" state: started enabled: true + +- name: Ensure tzdata package + package: + name: + - tzdata + state: present + when: + - ntp_timezone + +- name: Set timezone + timezone: + name: "{{ ntp_timezone }}" + when: + - ntp_timezone diff --git a/tests/files/packet_almalinux8-calico.yml b/tests/files/packet_almalinux8-calico.yml index f9ab1299d..1df4a64e5 100644 --- a/tests/files/packet_almalinux8-calico.yml +++ b/tests/files/packet_almalinux8-calico.yml @@ -12,6 +12,7 @@ loadbalancer_apiserver_type: haproxy # NTP mangement ntp_enabled: true +ntp_timezone: Etc/UTC ntp_manage_config: true ntp_tinker_panic: true ntp_force_sync_immediately: true