summaryrefslogtreecommitdiffstats
path: root/tasks/main.yml
blob: 491c04d75efbe29f57d1ee15f6ffd2e6c7dc810d (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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
---
- name: Include OS-specific variables.
  include_vars: "{{ ansible_os_family }}.yml"

- name: Configure timezone (For Ansible 2.2+)
  timezone:
    name: "{{ ntp_timezone }}"
  when: ansible_version.full >= "02.02.00.00"

- name: Set the correct timezone. (For Ansible prior 2.2)
  file:
    src: "/usr/share/zoneinfo/{{ ntp_timezone }}"
    dest: /etc/localtime
    state: link
    force: yes
  when: ansible_version.full < "02.02.00.00"

# Debian family OSes also have an /etc/timezone file.
- name: Set timezone in /etc/timezone file. (For Ansible prior 2.2)
  template:
    src: timezone.j2
    dest: /etc/timezone
    force: yes
  when:
    - ansible_os_family == 'Debian'
    - ansible_version.full < "02.02.00.00"

- name: Install NTP.
  package:
    name: ntp
    state: present

- name: Ensure NTP is running and enabled as configured.
  service:
    name: "{{ ntp_daemon }}"
    state: started
    enabled: yes
  when: ntp_enabled

- name: Ensure NTP is stopped and disabled as configured.
  service:
    name: "{{ ntp_daemon }}"
    state: stopped
    enabled: no
  when: not ntp_enabled

- name: Generate ntp.conf file
  template:
    src: ntp.conf.j2
    dest: /etc/ntp.conf
  notify: restart ntp
  when: ntp_manage_config