All HowTo's Ansible Ansible & Terraform Automation

Ansible to Set The Time with NTPdate

This article shows how to install and configure the NTP client using Ansible. I’ve cheated a little by using the “ntpdate” command rather than a service. But i find this more reliable.

The following is the yml file:

- hosts: all

  sudo: yes


  - name: Install ntpdate
      name: ntpdate
      state: latest

  - copy:
      src: files/cron.ntpdate
      dest: /etc/cron.d/cron.ntpdate
      owner: root
      group: root
      mode: 0644

And the file “./files/cron.ntpdate” that will be used for the cron-job:

0,11 * * * * root /usr/sbin/ntpdate

The above should solve your problems.

Leave a Reply

Your email address will not be published. Required fields are marked *