public inbox for kdevops@lists.linux.dev
 help / color / mirror / Atom feed
* [PATCH] devconfig: fix setting node timezone
@ 2024-04-08 22:25 Luis Chamberlain
  2024-04-09  0:53 ` Chuck Lever
  0 siblings, 1 reply; 9+ messages in thread
From: Luis Chamberlain @ 2024-04-08 22:25 UTC (permalink / raw)
  To: kdevops; +Cc: Luis Chamberlain

It turns out that just relying on the clock offset being set won't
ensure we have the right time set on the nodes, so when timectl is
enabled for NTP, we still need to set the timezone on the nodes based
on the hypervisor to be very sure we get the right time.

Below is an example where the clock offset XML settings were set on
guests with guestfs and yet the timezone on the nodes was set to
Eastern. To fix this we must keep a kconfig option which matches the
hypervisor, and use that value on the nodes to set the timezone.

mcgrof@some-hypervisor-01 /xfs1/base/kdevops (git::main)$ grep "clock offset" guestfs/base-xfs-nocrc/base-xfs-nocrc.xml
  <clock offset='localtime'>
mcgrof@some-hypervisor-01 /xfs1/base/kdevops (git::main)$ ssh base-xfs-reflink timedatectl
               Local time: Mon 2024-04-08 17:32:38 EDT
           Universal time: Mon 2024-04-08 21:32:38 UTC
                 RTC time: Mon 2024-04-08 21:32:38
                Time zone: US/Eastern (EDT, -0400)
System clock synchronized: yes
              NTP service: active
          RTC in local TZ: no
mcgrof@some-hypervisor-01 /xfs1/base/kdevops (git::main)$ timedatectl
               Local time: Mon 2024-04-08 21:32:42 UTC
           Universal time: Mon 2024-04-08 21:32:42 UTC
                 RTC time: Mon 2024-04-08 21:32:42
                Time zone: UTC (UTC, +0000)
System clock synchronized: yes
              NTP service: active
          RTC in local TZ: no

Fixes: de233a386941 ("devconfig: Remove DEVCONFIG_ENABLE_SYSTEMD_TIMESYNCD_TIMEZONE"
Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
---
 Makefile.min_deps                           | 1 +
 kconfigs/Kconfig.ansible_provisioning       | 4 ++++
 playbooks/roles/devconfig/defaults/main.yml | 1 +
 playbooks/roles/devconfig/tasks/main.yml    | 9 +++++++++
 scripts/systemd-timesync.Makefile           | 1 +
 5 files changed, 16 insertions(+)

diff --git a/Makefile.min_deps b/Makefile.min_deps
index 9d8f205799c4..ce0a82595074 100644
--- a/Makefile.min_deps
+++ b/Makefile.min_deps
@@ -10,6 +10,7 @@ BINARY_DEPS += sudo
 BINARY_DEPS += make
 BINARY_DEPS += nc
 BINARY_DEPS += ansible-playbook
+BINARY_DEPS += timedatectl
 
 BINARY_DEPS_VCHECKS := $(subst $(TOPDIR)/,,$(wildcard $(TOPDIR)/scripts/version_check/*))
 
diff --git a/kconfigs/Kconfig.ansible_provisioning b/kconfigs/Kconfig.ansible_provisioning
index 82a6f822c3f5..347992e24ab2 100644
--- a/kconfigs/Kconfig.ansible_provisioning
+++ b/kconfigs/Kconfig.ansible_provisioning
@@ -217,6 +217,10 @@ config DEVCONFIG_ENABLE_SYSTEMD_TIMESYNCD
 
 if DEVCONFIG_ENABLE_SYSTEMD_TIMESYNCD
 
+config DEVCONFIG_SYSTEMD_TIMESYNCD_TIMEZONE
+	string
+	default $(shell, timedatectl show -p Timezone --value)
+
 config DEVCONFIG_ENABLE_SYSTEMD_TIMESYNCD_NTP
 	bool "Enable systemd-timesyncd NTP"
 	default y
diff --git a/playbooks/roles/devconfig/defaults/main.yml b/playbooks/roles/devconfig/defaults/main.yml
index b48b4cce8e00..3fe2605c87e8 100644
--- a/playbooks/roles/devconfig/defaults/main.yml
+++ b/playbooks/roles/devconfig/defaults/main.yml
@@ -50,6 +50,7 @@ devconfig_systemd_journal_remote_url: "http://192.168.124.1"
 devconfig_systemd_journal_remote_path: "/var/log/journal/remote/"
 
 devconfig_enable_systemd_timesyncd: False
+devconfig_systemd_timesyncd_timezone: "UTC"
 devconfig_enable_systemd_timesyncd_ntp: False
 devconfig_enable_systemd_timesyncd_ntp_google: False
 devconfig_enable_systemd_timesyncd_ntp_debian: False
diff --git a/playbooks/roles/devconfig/tasks/main.yml b/playbooks/roles/devconfig/tasks/main.yml
index fec6ea3b5939..a76106b2a997 100644
--- a/playbooks/roles/devconfig/tasks/main.yml
+++ b/playbooks/roles/devconfig/tasks/main.yml
@@ -526,6 +526,15 @@
   when:
     - devconfig_enable_systemd_timesyncd_ntp|bool
 
+- name: Override timezone on nodes
+  tags: [ 'timesyncd' ]
+  become: yes
+  become_flags: 'su - -c'
+  become_method: sudo
+  command: "timedatectl set-timezone {{ devconfig_systemd_timesyncd_timezone }}"
+  when:
+    - devconfig_enable_systemd_timesyncd_ntp|bool
+
 - name: Restart systemd-timesyncd.service on the client
   become: yes
   become_flags: 'su - -c'
diff --git a/scripts/systemd-timesync.Makefile b/scripts/systemd-timesync.Makefile
index 11950cd9e598..d11d135113d8 100644
--- a/scripts/systemd-timesync.Makefile
+++ b/scripts/systemd-timesync.Makefile
@@ -2,6 +2,7 @@
 
 ifeq (y,$(CONFIG_DEVCONFIG_ENABLE_SYSTEMD_TIMESYNCD))
 ANSIBLE_EXTRA_ARGS += devconfig_enable_systemd_timesyncd='True'
+ANSIBLE_EXTRA_ARGS_DIRECT += devconfig_systemd_timesyncd_timezone='$(subst ",,$(CONFIG_DEVCONFIG_SYSTEMD_TIMESYNCD_TIMEZONE))'
 
 ifeq (y,$(CONFIG_DEVCONFIG_ENABLE_SYSTEMD_TIMESYNCD_NTP))
 ANSIBLE_EXTRA_ARGS += devconfig_enable_systemd_timesyncd_ntp='True'
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2024-04-11  0:53 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-08 22:25 [PATCH] devconfig: fix setting node timezone Luis Chamberlain
2024-04-09  0:53 ` Chuck Lever
2024-04-09  3:36   ` Luis Chamberlain
2024-04-09 13:29     ` Chuck Lever
2024-04-09 14:22       ` Chuck Lever
2024-04-09 16:51         ` Chuck Lever
2024-04-10 15:43       ` Luis Chamberlain
2024-04-10 15:45         ` Chuck Lever
2024-04-11  0:53           ` Luis Chamberlain

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox