Setting NTP on Ubuntu servers in AWS with ansible

A simple, but often overlooked task when running a bunch of servers is making sure they’re all time-synced. Thankfully AWS makes sure a reliable time source is always accessible from your servers. The documentation from AWS is linked below.

Here’s a simple ansible playbook to get you started:

- hosts: all
  remote_user: youruser
  become: true
  become_user: root
  become_method: sudo
  become_flags: '-i'
  - name: install chrony
            name: chrony
            state: latest
  - name: set chrony ntp config
            src: /etc/ansible/resources/chrony.conf
            dest: /etc/chrony/chrony.conf
            owner: root
            group: root
            mode: 0644
  - name: enable chrony             
            name: chrony.service
            state: started
            enabled: yes

Make sure you replace the source of the chrony.conf file with the appropriate file. My chrony.conf is linked below. The link-local address should be included to take advantage of AWS’s time servers.

server prefer iburst minpoll 4 maxpoll 4
pool        iburst maxsources 4
keyfile /etc/chrony/chrony.keys
driftfile /var/lib/chrony/chrony.drift
#log tracking measurements statistics
logdir /var/log/chrony
maxupdateskew 100.0
makestep 1 3

This should result in your servers having the correct time, assuming you set the time-zone correctly.

Good luck!


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s