Alan Orth
0a92f3ae8f
This was new in Ansible 2.2 but I didn't notice until now. All of our servers are running distributions with systemd so let's just use this.
26 lines
935 B
YAML
26 lines
935 B
YAML
---
|
|
# 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: Start and enable systemd's NTP client
|
|
when: ansible_service_mgr == 'systemd'
|
|
systemd: name=systemd-timesyncd state=started 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:
|