roles/common: Add a dedicated playbook for ntp tasks
Hosts with systemd should use its NTP client and explicitly remove the `ntp` packages. Hosts with older init systems should use `ntp`.
This commit is contained in:
parent
8851f8f631
commit
5f656285c0
@ -8,8 +8,7 @@
|
|||||||
command: /usr/bin/timedatectl set-timezone {{ timezone }}
|
command: /usr/bin/timedatectl set-timezone {{ timezone }}
|
||||||
tags: timezone
|
tags: timezone
|
||||||
|
|
||||||
- name: Enable NTP
|
- include: ntp.yml
|
||||||
service: name=systemd-timesyncd enabled=yes
|
|
||||||
tags: ntp
|
tags: ntp
|
||||||
|
|
||||||
- include: packages_{{ ansible_distribution }}.yml
|
- include: packages_{{ ansible_distribution }}.yml
|
||||||
|
25
roles/common/tasks/ntp.yml
Normal file
25
roles/common/tasks/ntp.yml
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
---
|
||||||
|
# Hosts running Ubuntu 16.04 or Debian 8 use the systemd init system and should
|
||||||
|
# use timedatectl as a network time client instead of the standalone ntp client.
|
||||||
|
# Earlier versions of those distros should use the ntp/ntpd package.
|
||||||
|
|
||||||
|
- name: Set timezone
|
||||||
|
when: timezone is defined and ansible_service_mgr == 'systemd'
|
||||||
|
command: /usr/bin/timedatectl set-timezone {{ timezone }}
|
||||||
|
tags: timezone
|
||||||
|
|
||||||
|
- name: Enable systemd's NTP client
|
||||||
|
when: ansible_service_mgr == 'systemd'
|
||||||
|
service: name=systemd-timesyncd enabled=yes
|
||||||
|
|
||||||
|
- name: Uninstall ntp on modern Ubuntu/Debian
|
||||||
|
apt: name=ntp state=absent update_cache=yes
|
||||||
|
when: ansible_os_family == 'Debian' and ansible_service_mgr == 'systemd'
|
||||||
|
tags: packages
|
||||||
|
|
||||||
|
- name: Install ntp on old Ubuntu/Debian
|
||||||
|
apt: name=ntp state=present update_cache=yes
|
||||||
|
when: ansible_os_family == 'Debian' and ansible_service_mgr != 'systemd'
|
||||||
|
tags: packages
|
||||||
|
|
||||||
|
# vim: set ts=2 sw=2:
|
Loading…
Reference in New Issue
Block a user