# {{ ansible_managed }}

{% for value in timesync_ntp_servers %}
{{ 'pool' if 'pool' in value and value['pool'] else 'server' }} {{
value['hostname'] }}{{
' minpoll {0}'.format(value['minpoll']) if 'minpoll' in value else '' }}{{
' maxpoll {0}'.format(value['maxpoll']) if 'maxpoll' in value else '' }}{{
' iburst' if 'iburst' in value and value else '' }}
{% endfor %}

{% if timesync_step_threshold != 0.0 %}
# Allow the system clock to be stepped in the first three updates.
makestep {{ timesync_step_threshold if timesync_step_threshold > 0.0 else '1.0' }} 3

{% endif %}
# Enable kernel synchronization of the real-time clock (RTC).
rtcsync

{% if timesync_min_sources > 1 %}
# Increase the minimum number of selectable sources required to adjust
# the system clock.
minsources {{ timesync_min_sources }}

{% endif %}
# Record the rate at which the system clock gains/losses time.
driftfile /var/lib/chrony/drift

{% if timesync_chrony_version.stdout|version_compare('2.0', '<') %}
# Decrease weight of stratum in source selection.
stratumweight 0.001

# Listen for commands only on localhost.
bindcmdaddress 127.0.0.1
bindcmdaddress ::1

{% endif %}
{% if timesync_chrony_version.stdout|version_compare('2.2', '<') %}
# Specify file containing keys for NTP and command authentication.
keyfile /etc/chrony.keys

# Specify ID of command key.
commandkey 1

# Generate command key if missing.
generatecommandkey

{% endif %}
