mirror of
https://github.com/freeipa/ansible-freeipa.git
synced 2026-06-23 09:14:43 +00:00
ipaclient_setup_ntp: Use time sync code from 4.6.4 if sync_time is not defined
The FreeIPA versions since 4.7.0 are using chrony and also the new sync_time function for time synchronization which has been added to ipaclient/install/client.py. The old version in ipaclient_setup_ntp has been updated to the code that has been used in 4.6.4.
This commit is contained in:
@@ -115,11 +115,11 @@ def main():
|
|||||||
cli_domain = module.params.get('domain')
|
cli_domain = module.params.get('domain')
|
||||||
|
|
||||||
options.conf_ntp = not options.no_ntp
|
options.conf_ntp = not options.no_ntp
|
||||||
|
options.debug = False
|
||||||
|
|
||||||
fstore = sysrestore.FileStore(paths.IPA_CLIENT_SYSRESTORE)
|
fstore = sysrestore.FileStore(paths.IPA_CLIENT_SYSRESTORE)
|
||||||
statestore = sysrestore.StateFile(paths.IPA_CLIENT_SYSRESTORE)
|
statestore = sysrestore.StateFile(paths.IPA_CLIENT_SYSRESTORE)
|
||||||
|
|
||||||
ntp_servers = [ ]
|
|
||||||
synced_ntp = False
|
synced_ntp = False
|
||||||
if sync_time is not None:
|
if sync_time is not None:
|
||||||
if options.conf_ntp:
|
if options.conf_ntp:
|
||||||
@@ -133,40 +133,43 @@ def main():
|
|||||||
else:
|
else:
|
||||||
logger.info("Skipping chrony configuration")
|
logger.info("Skipping chrony configuration")
|
||||||
|
|
||||||
elif not options.on_master and options.conf_ntp:
|
else:
|
||||||
# Attempt to sync time with IPA server.
|
ntp_srv_servers = [ ]
|
||||||
# If we're skipping NTP configuration, we also skip the time sync here.
|
if not options.on_master and options.conf_ntp:
|
||||||
# We assume that NTP servers are discoverable through SRV records
|
# Attempt to sync time with IPA server.
|
||||||
# in the DNS.
|
# If we're skipping NTP configuration, we also skip the time sync here.
|
||||||
# If that fails, we try to sync directly with IPA server,
|
# We assume that NTP servers are discoverable through SRV records
|
||||||
# assuming it runs NTP
|
# in the DNS.
|
||||||
if not options.ntp_servers:
|
# If that fails, we try to sync directly with IPA server,
|
||||||
# Detect NTP servers
|
# assuming it runs NTP
|
||||||
|
logger.info('Synchronizing time with KDC...')
|
||||||
ds = ipadiscovery.IPADiscovery()
|
ds = ipadiscovery.IPADiscovery()
|
||||||
ntp_servers = ds.ipadns_search_srv(cli_domain, '_ntp._udp',
|
ntp_srv_servers = ds.ipadns_search_srv(cli_domain, '_ntp._udp',
|
||||||
None, break_on_first=False)
|
None, break_on_first=False)
|
||||||
else:
|
synced_ntp = False
|
||||||
ntp_servers = options.ntp_servers
|
ntp_servers = ntp_srv_servers
|
||||||
|
|
||||||
# Attempt to sync time:
|
# use user specified NTP servers if there are any
|
||||||
# At first with given or dicovered time servers. If no ntp
|
if options.ntp_servers:
|
||||||
# servers have been given or discovered, then with the ipa
|
ntp_servers = options.ntp_servers
|
||||||
# server.
|
|
||||||
module.log('Synchronizing time ...')
|
for s in ntp_servers:
|
||||||
synced_ntp = False
|
synced_ntp = ntpconf.synconce_ntp(s, options.debug)
|
||||||
# use user specified NTP servers if there are any
|
if synced_ntp:
|
||||||
for s in ntp_servers:
|
break
|
||||||
synced_ntp = timeconf.synconce_ntp(s, False)
|
|
||||||
if synced_ntp:
|
if not synced_ntp and not options.ntp_servers:
|
||||||
break
|
synced_ntp = timeconf.synconce_ntp(cli_server[0], options.debug)
|
||||||
if not synced_ntp and not ntp_servers:
|
if not synced_ntp:
|
||||||
synced_ntp = timeconf.synconce_ntp(cli_server[0], False)
|
module.warn(
|
||||||
if not synced_ntp:
|
"Unable to sync time with NTP "
|
||||||
module.warn("Unable to sync time with NTP server")
|
"server, assuming the time is in sync. Please check "
|
||||||
|
"that 123 UDP port is opened.")
|
||||||
|
else:
|
||||||
|
logger.info('Skipping synchronizing time with NTP server.')
|
||||||
|
|
||||||
# Done
|
# Done
|
||||||
module.exit_json(changed=True,
|
module.exit_json(changed=synced_ntp)
|
||||||
synced_ntp=synced_ntp)
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|||||||
Reference in New Issue
Block a user