I have a bunch of rhel servers and I must make sure all of then are synchronized in time. They all are running chronyd service.

My question is, is there any utility to check this via a command? Does anyone know about an ansible module to do this? I didn't any found.

All I want is to check if all servers are running with the same time in a strict and efficient way. Probably something similar to ntpdate would suit me.

Thanks in advance!

  • 1
    Have you looked at the documentation for chrony, which will tell you how to determine whether it's synchronised or not.
    – roaima
    Nov 27, 2019 at 21:40

1 Answer 1


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

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
   src: <global chrony.conf on your ansible server>
   dest: /etc/chrony.conf
   backup: yes
  when: ntpstat_rc.rc != 0

- name: Restart chrony service
   name: chronyd
   state: restarted
  when: ntpstat_rc.rc != 0

I hope this helps.


  • Absolutely interesting! Cheers!
    – DrunkCoder
    Dec 20, 2019 at 16:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.