---
  - name: Set up time zone
    become: yes
    register: localtime
    file:
      src: "/usr/share/zoneinfo/{{ time_zone }}"
      dest: /etc/localtime
      state: link

  - name: Remove legacy NTP services
    become: yes
    ignore_errors: yes
    service:
        name: "{{ item }}"
        state: stopped
        enabled: no
    loop:
        - ntpd
        - openntpd

  - name: Remove legacy NTP packages
    become: yes
    package:
        name:
            - ntp
            - openntpd
        state: absent

  - name: Install NTP packages
    become: yes
    package:
        name: chrony
        state: present

  - name: Start NTP service
    become: yes
    service:
      name: chronyd
      state: started
      enabled: yes
