---

- name: "Install NTP package on EL"
  yum: 
    name: ntp
    state: present
  when: ansible_os_family == 'RedHat'

- name: "Install NTP package on Debian/Ubuntu"
  apt:
    name: ntp
    state: present
  when: ansible_os_family == 'Debian'

- name: "Check if clock is synchronised"
  shell: "ntpstat"
  register: status
  ignore_errors: yes # command will fail if service not running
  
  # Force clock sync if it is not
- include: sync-clock.yml
  when: status.rc != 0

- name: "Ensure ntp service is started"
  service:
    name: ntpd
    state: started
    enabled: yes

---

- name: "Install NTP package on EL"
  yum: 
    name: ntp
    state: present
  when: ansible_os_family == 'RedHat'

- name: "Install NTP package on Debian/Ubuntu"
  apt:
    name: ntp
    state: present
  when: ansible_os_family == 'Debian'

- name: "Check if clock is synchronised"
  shell: "ntpstat"
  register: status
  ignore_errors: yes # command will fail if service not running
  
  # Force clock sync if it is not
- include: sync-clock.yml
  when: status.rc != 0

- name: "Ensure ntp service is started"
  service:
    name: ntpd
    state: started
    enabled: yes
  when: ansible_os_family == 'RedHat'

- name: "Ensure ntp service is started"
  service:
    name: ntp
    state: started
    enabled: yes
  when: ansible_os_family == 'Debian'


Correct name of service for Debian
Correct name of service for Debian
