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
tasks:
- name: Install Chrony package
dnf:
name: chrony
state: present
when: ansible_distribution == "Rocky"
- name: Configure Chrony servers
lineinfile:
path: /etc/chrony.conf
line: "server sg.pool.ntp.org iburst"
insertafter: '^#.*server 3.centos.pool.ntp.org iburst'
state: present
when: ansible_distribution == "Rocky"
- name: Enable Chrony service
service:
name: chronyd
state: started
enabled: yes
when: ansible_distribution == "Rocky"