Check if chrony is synchronised with commands
You can use chrony specific commands to check the ntp status.
If you want to see the information for the current ntp server use
chronyc tracking
To display all ntp servers
chronyc sources
For more information see:
fedora - check if chrony is synchronised
Combination with ansible
There is no ansible module, but there is another way.
You should still have the ntpstat utility which also works for chrony.
The return codes give information about the ntp status. 0 for clock synchronized, 1 for not synchronized and 2 if clock state is indeterminant. See manpage
You can verify that
ntpstat
echo $?
If you use the ansible command module to run ntpstat it fails by default if the return code of the command is not 0. So in this case we can use this to our advantage.
Make a simple playbook which runs the command ntpstat.
- name: Check if chrony is synchronized
command: ntpstat
Run the playbook for the desired host group. All hosts that fail have not a synchronized ntp.
To go further you could copy the global chrony configuration (chrony.conf) to all hosts and restart the chronyd service with ansible, if the return code is not 0.
- name: Check if chrony is synchronized
command: ntpstat
register: ntpstat_rc
ignore_errors: true
- name: Copy chrony configuration
copy:
src: <global chrony.conf on your ansible server>
dest: /etc/chrony.conf
backup: yes
when: ntpstat_rc.rc != 0
- name: Restart chrony service
systemd:
name: chronyd
state: restarted
when: ntpstat_rc.rc != 0
I hope this helps.
Cheers
chrony
, which will tell you how to determine whether it's synchronised or not.