From 0ef4528c90547055ad204509cb36182b603963ab Mon Sep 17 00:00:00 2001 From: Pierre Riteau Date: Mon, 7 Oct 2024 22:41:09 +0200 Subject: [PATCH] Support forcing time synchronisation This adds support for forcing time synchronisation after configuring chrony if ntp_force_sync is changed to True. Change-Id: I4e0fd325e2ceb698f1f959bc060b68bd629750e0 Co-Authored-By: Will Szumski (cherry picked from commit 9c6b4477f84b9360eafe88fe26a3dd230b0f7c50) --- ansible/roles/ntp/defaults/main.yml | 5 ++++- ansible/roles/ntp/tasks/main.yml | 4 ++++ ansible/roles/ntp/tasks/sync.yml | 17 +++++++++++++++++ .../notes/ntp-force-sync-d22bfbd63c7be026.yaml | 5 +++++ 4 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 ansible/roles/ntp/tasks/sync.yml create mode 100644 releasenotes/notes/ntp-force-sync-d22bfbd63c7be026.yaml diff --git a/ansible/roles/ntp/defaults/main.yml b/ansible/roles/ntp/defaults/main.yml index dea948074..aa7558b19 100644 --- a/ansible/roles/ntp/defaults/main.yml +++ b/ansible/roles/ntp/defaults/main.yml @@ -1,5 +1,8 @@ --- -ntp_actions: ["validate", "prepare", "deploy"] +ntp_actions: ["validate", "prepare", "deploy", "sync"] + +# Do not jump clock by default +ntp_force_sync: False ntp_service_disable_list: - ntp.service diff --git a/ansible/roles/ntp/tasks/main.yml b/ansible/roles/ntp/tasks/main.yml index efb655192..731ea3730 100644 --- a/ansible/roles/ntp/tasks/main.yml +++ b/ansible/roles/ntp/tasks/main.yml @@ -10,3 +10,7 @@ - name: Deploy service include_tasks: deploy.yml when: '"deploy" in ntp_actions' + +- name: Synchronise time + include_tasks: sync.yml + when: '"sync" in ntp_actions' diff --git a/ansible/roles/ntp/tasks/sync.yml b/ansible/roles/ntp/tasks/sync.yml new file mode 100644 index 000000000..e679d3915 --- /dev/null +++ b/ansible/roles/ntp/tasks/sync.yml @@ -0,0 +1,17 @@ +--- +- name: Force time synchronisation + become: True + block: + - name: Configure burst + command: chronyc 'burst 4/4' + + - name: Step the clock + command: chronyc makestep + + - name: Wait before hardware clock synchronisation + pause: + seconds: 5 + + - name: Force hardware clock synchronisation + command: hwclock --systohc + when: ntp_force_sync | bool diff --git a/releasenotes/notes/ntp-force-sync-d22bfbd63c7be026.yaml b/releasenotes/notes/ntp-force-sync-d22bfbd63c7be026.yaml new file mode 100644 index 000000000..81184d236 --- /dev/null +++ b/releasenotes/notes/ntp-force-sync-d22bfbd63c7be026.yaml @@ -0,0 +1,5 @@ +--- +features: + - | + Supports forcing time synchronisation after configuring ``chrony`` if + ``ntp_force_sync`` is changed to ``True``.