summaryrefslogtreecommitdiff
path: root/roles/core/ntp/tasks/Debian_systemd-timesyncd.yml
blob: 5fa605101c26c393f2de2cfe0d56fdf7ae7ab93e (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
32
---
- 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_release | debian_release_compare('>', 'buster'))) 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