If you are using Ansible to configure chrony which is a versatile implementation of the Network Time Protocol (NTP), you may want to take a look at the simple script below
---
- hosts: all
remote_user: ansible
tasks:
- name: Ensure NTP is installed
yum:
name: ntp
state: present
become: True
- name: Ensure the timezone is set to UTC
file:
src: /usr/share/zoneinfo/GMT
dest: /etc/localtime
state: link
become: True
- name: Ensure the NTP service is running and enabled
service:
name: ntpd
state: started
enabled: True
become: True
Prerequisites Step 1: Endure you are in the correct time zone
# timedatectl
Local time: Wed 2022-04-20 10:04:44 +08
Universal time: Wed 2022-04-20 02:04:44 UTC
RTC time: Wed 2022-04-20 02:04:44
Time zone: Asia/Singapore (+08, +0800)
System clock synchronized: no
NTP service: active
RTC in local TZ: no
In Rocky Linux 8.5, the ntp package is no longer supported and it is implemented by the chronyd (a daemon that runs in user-space) which is provided in the chrony package.
chrony works both as an NTP server and as an NTP client, which is used to synchronize the system clock with NTP servers.
To install the chrony suite, use the DNF Package Manager.
[root@h00 etc]# timedatectl
Local time: Wed 2022-04-20 10:19:56 +08
Universal time: Wed 2022-04-20 02:19:56 UTC
RTC time: Wed 2022-04-20 02:19:56
Time zone: Asia/Singapore (+08, +0800)
System clock synchronized: yes
NTP service: active
RTC in local TZ: no
Setting up NTP Client Using Chrony in Rocky Linux 8.5
# vim /etc/chrony.conf
.....
pool sg.pool.ntp.org iburst
.....
# systemctl restart chronyd
Show the current time sources that chronyd is accessing