Network Time Protocol (NTP) - cloud-init 25.1.2 documentation (original) (raw)

View this page

Toggle table of contents sidebar

The NTP module configures NTP services. If NTP is not installed on the system, but NTP configuration is specified, NTP will be installed.

For a full list of keys, refer to the NTP module schema.

Available keys:

Each server in the list will be added in list-order in the format:

[pool|server] iburst

If no servers or pools are defined but NTP is enabled, then cloud-init will render the distro default list of pools:

pools = [ '0.{distro}.pool.ntp.org', '1.{distro}.pool.ntp.org', '2.{distro}.pool.ntp.org', '3.{distro}.pool.ntp.org', ]

So putting these together, we can see a straightforward example:

#cloud-config ntp: pools: ['0.company.pool.ntp.org', '1.company.pool.ntp.org', 'ntp.myorg.org'] servers: ['my.ntp.server.local', 'ntp.ubuntu.com', '192.168.23.2']

Override NTP with chrony

Here we override NTP with chrony configuration on Ubuntu. The example uses cloud-init’s default chrony configuration.

1#cloud-config 2ntp: 3 enabled: true 4 ntp_client: chrony # Uses cloud-init default chrony configuration

Custom NTP client config

This example provides a custom NTP client configuration.

1#cloud-config 2ntp: 3 enabled: true 4 ntp_client: myntpclient 5 config: 6 confpath: /etc/myntpclient/myntpclient.conf 7 check_exe: myntpclientd 8 packages: 9 - myntpclient 10 service_name: myntpclient 11 template: | 12 ## template:jinja 13 # My NTP Client config 14 {% if pools -%}# pools{% endif %} 15 {% for pool in pools -%} 16 pool {{pool}} iburst 17 {% endfor %} 18 {%- if servers %}# servers 19 {% endif %} 20 {% for server in servers -%} 21 server {{server}} iburst 22 {% endfor %} 23 {% if peers -%}# peers{% endif %} 24 {% for peer in peers -%} 25 peer {{peer}} 26 {% endfor %} 27 {% if allow -%}# allow{% endif %} 28 {% for cidr in allow -%} 29 allow {{cidr}} 30 {% endfor %} 31 pools: [0.int.pool.ntp.org, 1.int.pool.ntp.org, ntp.myorg.org] 32 servers: 33 - ntp.server.local 34 - ntp.ubuntu.com 35 - 192.168.23.2 36 allow: 37 - 192.168.23.0/32 38 peers: 39 - km001 40 - km002