summaryrefslogtreecommitdiffstats
path: root/roles/common/tasks/ntp.yml
blob: 2ff9e49accfa3e96dfe21a0b0664a42b55a1dbf6 (plain)
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
33
- name: Remove ntp package
  apt: pkg=ntp state={{ state }} purge=yes
  vars:
    state: "{{ ('NTP_master' in group_names) | ternary('present', 'absent') }}"

- name: Install systemd-timesyncd package
  apt: pkg=systemd-timesyncd state=present purge=yes
  when: "'NTP_master' not in group_names"

- name: Create /etc/systemd/timesyncd.conf.d
  file: path=/etc/systemd/timesyncd.conf.d
        state=directory
        owner=root group=root
        mode=0755
  when: "'NTP_master' not in group_names"

- name: Configure ntp
  template: src=etc/{{ conf }}.j2
            dest=/etc/{{ conf }}
            owner=root group=root
            mode=0644
  vars:
    conf: "{{ ('NTP_master' in group_names) | ternary('ntp.conf', 'systemd/timesyncd.conf.d/fripost.conf') }}"
    service: "{{ ('NTP_master' in group_names) | ternary('ntp', 'systemd-timesyncd') }}"
  notify:
    - Restart {{ service }}

- meta: flush_handlers

- name: Start and enable ntp
  service: name={{ service }}.service state=started enabled=true
  vars:
    service: "{{ ('NTP_master' in group_names) | ternary('ntp', 'systemd-timesyncd') }}"