tripleo-heat-templates/firstboot/userdata_timesync.yaml
Alex Schultz 5341e56992 Add chrony waitsync back in
This is a revert of 373a27163e because
makestep does not fail if the ntp servers are unavailable. This change
adds waitsync back in so it fails if the servers are unavilable but
leaves the makestep in place which should force the sync.  If the
servers are unavailable, the waitsync should catch it. If they are
available waitsync should be a relative noop because the makestep would
sync the system.  The waitsync has been increased to 5 minutes (from 200
seconds). waitsync will wait 30 times with an interval of 10 seconds
between checks.

Depends-On: https://review.opendev.org/c/openstack/ansible-role-collect-logs/+/822848
Depends-On: https://review.opendev.org/c/openstack/tripleo-ci/+/822857
Closes-Bug: #1955414
Change-Id: I4ac9210f6533e6826b2814f72b7271b43fdca267
(cherry picked from commit 8d46c9c381)
2021-12-23 13:53:52 -07:00

99 lines
3.0 KiB
YAML

heat_template_version: wallaby
parameters:
NtpServer:
default: ['0.pool.ntp.org', '1.pool.ntp.org', '2.pool.ntp.org', '3.pool.ntp.org']
description: NTP servers list. Defaulted to a set of pool.ntp.org servers
in order to have a sane default for Pacemaker deployments when
not configuring this parameter by default.
type: comma_delimited_list
NtpPool:
default: []
description: NTP pool list. Defaults to [], so only NtpServer is used by
default.
type: comma_delimited_list
NtpService:
default: chrony
description: NTP Service to use for the timesync bootstrap.
type: string
description: >
Uses cloud-init to bootstrap timesync configuration to ensure it is done
as soon as possible. We do additional and more complex configurations as
part of the deployment itself.
conditions:
use_chrony: {equals: [{get_param: NtpService}, 'chrony']}
resources:
userdata:
type: OS::Heat::MultipartMime
properties:
parts:
- config: {get_resource: timesync_chrony}
- config: {get_resource: timesync_sync}
# chrony sync needs chrony to be configured, if not chrony just exit
timesync_chrony:
type: OS::Heat::SoftwareConfig
properties:
config:
str_replace:
template: |
#!/bin/bash
if [ "$service" != "chrony" ]; then
exit 0
fi
set -x
SERVERS="$ntp_servers"
POOLS="$ntp_pools"
systemctl is-active --quiet chronyd || systemctl start chronyd
for server in $SERVERS; do
chronyc add server "${server}" iburst
done
for pool in $POOLS; do
chronyc add server "${pool}" iburst
done
chronyc sources
params:
$ntp_servers:
list_join: [' ', {get_param: NtpServer}]
$ntp_pools:
list_join: [' ', {get_param: NtpPool}]
$service: {get_param: NtpService}
# attempt a timesync on boot to ensure the time has been synced
timesync_sync:
type: OS::Heat::SoftwareConfig
properties:
config:
str_replace:
template: |
#!/bin/bash
set -x
if [ "$service" = "chrony" ]; then
if command -v chronyc >/dev/null; then
chronyc makestep
chronyc waitsync 30
else
echo "No chronyc available, skipping sync"
fi
elif [ "$service" = "ntp" ]; then
if command -v ntpdate >/dev/null; then
ntpdate -u $ntp_servers
else
echo "No ntpdate available, skipping sync"
fi
fi
hwclock --systohc --utc
params:
$service: {get_param: NtpService}
$ntp_servers:
list_join: [' ', {get_param: NtpServer}]
outputs:
OS::stack_id:
value: {get_resource: userdata}