From e98770a43d89ba446dd59e3c4b098a5a68637013 Mon Sep 17 00:00:00 2001 From: Kevin Carter Date: Wed, 5 Feb 2025 15:46:30 -0600 Subject: [PATCH] chore: add timesyncd support this change will ensure that we're using timesyncd when configuring hosts. Signed-off-by: Kevin Carter --- ansible/inventory/genestack/group_vars/all/all.yml | 4 ++-- ansible/roles/host_setup/defaults/main.yml | 5 +++++ ansible/roles/host_setup/handlers/main.yml | 6 ++++++ ansible/roles/host_setup/tasks/configure_hosts.yml | 14 ++++++++++++++ ansible/roles/host_setup/tasks/main.yml | 9 --------- .../roles/host_setup/templates/timesyncd.conf.j2 | 8 ++++++++ ansible/roles/host_setup/vars/ubuntu.yml | 1 + 7 files changed, 36 insertions(+), 11 deletions(-) create mode 100644 ansible/roles/host_setup/templates/timesyncd.conf.j2 diff --git a/ansible/inventory/genestack/group_vars/all/all.yml b/ansible/inventory/genestack/group_vars/all/all.yml index e6b52210..615135af 100644 --- a/ansible/inventory/genestack/group_vars/all/all.yml +++ b/ansible/inventory/genestack/group_vars/all/all.yml @@ -124,8 +124,8 @@ kube_webhook_token_auth_url_skip_tls_verify: false ## NTP Settings # Start the ntpd or chrony service and enable it at system boot. -ntp_enabled: true -ntp_manage_config: true +ntp_enabled: false +ntp_manage_config: false ntp_servers: - "0.pool.ntp.org iburst" - "1.pool.ntp.org iburst" diff --git a/ansible/roles/host_setup/defaults/main.yml b/ansible/roles/host_setup/defaults/main.yml index f9beef4c..21934cf2 100644 --- a/ansible/roles/host_setup/defaults/main.yml +++ b/ansible/roles/host_setup/defaults/main.yml @@ -128,3 +128,8 @@ host_specific_kernel_modules: [] # Optional user defined list of sysctl options in the same dict item format as # above. user_kernel_options: [] + +# Limited to two servers, the first one is the primary and the second one is the backup. +host_ntp_server: + - 0.pool.ntp.org + - 1.pool.ntp.org diff --git a/ansible/roles/host_setup/handlers/main.yml b/ansible/roles/host_setup/handlers/main.yml index 9fc3f70f..b5075797 100644 --- a/ansible/roles/host_setup/handlers/main.yml +++ b/ansible/roles/host_setup/handlers/main.yml @@ -38,3 +38,9 @@ name: "queue_max.service" state: "restarted" enabled: true + +- name: Reload systemd-timesyncd + ansible.builtin.systemd: + name: systemd-timesyncd + state: reloaded + enabled: true diff --git a/ansible/roles/host_setup/tasks/configure_hosts.yml b/ansible/roles/host_setup/tasks/configure_hosts.yml index f4f16273..22adee7b 100644 --- a/ansible/roles/host_setup/tasks/configure_hosts.yml +++ b/ansible/roles/host_setup/tasks/configure_hosts.yml @@ -78,3 +78,17 @@ dest: /etc/systemd/system/queue_max.service mode: "0644" notify: Load and start queue_max service + +- name: Ensure timesyncd is running + ansible.builtin.service: + name: systemd-timesyncd + state: started + enabled: true + notify: Reload systemd-timesyncd + +- name: Create systemd-timesyncd configuration file + ansible.builtin.copy: + src: timesyncd.conf + dest: /etc/systemd/timesyncd.conf + mode: "0644" + notify: Reload systemd-timesyncd diff --git a/ansible/roles/host_setup/tasks/main.yml b/ansible/roles/host_setup/tasks/main.yml index 365ea75e..05746f52 100644 --- a/ansible/roles/host_setup/tasks/main.yml +++ b/ansible/roles/host_setup/tasks/main.yml @@ -121,12 +121,3 @@ until: install_packages is success retries: 5 delay: 2 - -# this is added to remove conflicts with systemd-timesyncd and ntpsec with kubespray installation -- name: Ensure conflicting time synchronization packages are removed - package: - name: - - ntpsec - - systemd-timesyncd - state: absent - purge: yes diff --git a/ansible/roles/host_setup/templates/timesyncd.conf.j2 b/ansible/roles/host_setup/templates/timesyncd.conf.j2 new file mode 100644 index 00000000..7b33bee6 --- /dev/null +++ b/ansible/roles/host_setup/templates/timesyncd.conf.j2 @@ -0,0 +1,8 @@ +[Time] +NTP={{ host_ntp_server | first }} +FallbackNTP={{ host_ntp_server | last }} +#RootDistanceMaxSec=5 +#PollIntervalMinSec=32 +#PollIntervalMaxSec=2048 +#ConnectionRetrySec=30 +#SaveIntervalSec=60 diff --git a/ansible/roles/host_setup/vars/ubuntu.yml b/ansible/roles/host_setup/vars/ubuntu.yml index a3e9b6ad..3e547cac 100644 --- a/ansible/roles/host_setup/vars/ubuntu.yml +++ b/ansible/roles/host_setup/vars/ubuntu.yml @@ -55,6 +55,7 @@ _host_distro_packages: - rsync - software-properties-common - sysstat + - systemd-timesyncd - time - vlan - wget