summaryrefslogtreecommitdiff
path: root/roles/core/ntp/tasks/Debian_systemd-timesyncd.yml
blob: 40c6629e7afff12f1c7df169c64ef88971c134d0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
---
- name: make sure ntp_server and ntp_refclocks is not defined
  assert:
    that:
    - ntp_refclocks is not defined
    - ntp_server is not defined
    msg: "systemd-timesyncd can not be used as a NTP server or sync to local clocks"

- name: install systemd-timesyncd
  when: (ansible_distribution == 'Debian' and (ansible_distribution_major_version | int) > 10) or (ansible_distribution == 'Ubuntu')
  apt:
    name: systemd-timesyncd
    state: present

- name: set ntp servers
  when:
  - ntp_client is defined
  - "'servers' in ntp_client"
  lineinfile:
    path: /etc/systemd/timesyncd.conf
    regexp: '^#?NTP='
    line: "NTP={{ ntp_client.servers | map(attribute='name') | join(' ') }}"
  notify: restart systemd-timesyncd

- name: un-set ntp servers
  when: "ntp_client is not defined or 'servers' not in ntp_client"
  lineinfile:
    path: /etc/systemd/timesyncd.conf
    regexp: '^#?NTP='
    line: "#NTP="
  notify: restart systemd-timesyncd