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``.