2016-08-25 13:19:51 +02:00
|
|
|
---
|
2019-07-01 23:12:32 +02:00
|
|
|
# Hosts running Ubuntu 16.04+ and Debian 9+ use systemd init system and should
|
2021-09-08 16:04:20 +02:00
|
|
|
# use systemd-timesyncd as a network time client instead of the standalone ntp
|
|
|
|
# client.
|
2016-08-25 13:19:51 +02:00
|
|
|
|
|
|
|
- name: Set timezone
|
|
|
|
when: timezone is defined and ansible_service_mgr == 'systemd'
|
|
|
|
command: /usr/bin/timedatectl set-timezone {{ timezone }}
|
|
|
|
tags: timezone
|
|
|
|
|
2021-09-08 16:04:46 +02:00
|
|
|
# Apparently some cloud images don't have this installed by default. From what
|
|
|
|
# I can see on existing servers, systemd-timesyncd is a standalone package on
|
|
|
|
# Ubuntu 20.04 and Debian 11.
|
|
|
|
- name: Install systemd-timesyncd
|
|
|
|
when: (ansible_distribution == 'Ubuntu' and ansible_distribution_version is version('20.04', '==')) or
|
|
|
|
(ansible_distribution == 'Debian' and ansible_distribution_version is version('11', '=='))
|
2022-09-10 17:09:12 +02:00
|
|
|
ansible.builtin.apt: name=systemd-timesyncd state=present cache_valid_time=3600
|
2021-09-08 16:04:46 +02:00
|
|
|
|
2017-11-02 17:55:20 +01:00
|
|
|
- name: Start and enable systemd's NTP client
|
2016-08-25 13:19:51 +02:00
|
|
|
when: ansible_service_mgr == 'systemd'
|
2022-09-10 17:09:12 +02:00
|
|
|
ansible.builtin.systemd: name=systemd-timesyncd state=started enabled=yes
|
2016-08-25 13:19:51 +02:00
|
|
|
|
|
|
|
- name: Uninstall ntp on modern Ubuntu/Debian
|
2022-09-10 17:09:12 +02:00
|
|
|
ansible.builtin.apt: name=ntp state=absent
|
2017-11-05 00:19:28 +01:00
|
|
|
when: ansible_service_mgr == 'systemd'
|
2016-08-25 13:19:51 +02:00
|
|
|
|
|
|
|
# vim: set ts=2 sw=2:
|