--- - name: set ntp service name depending on OS family block: - name: set ntp service name for Debian family set_fact: ntp_service_name: ntp when: ansible_os_family == 'Debian' - name: set ntp service name for Red Hat family set_fact: ntp_service_name: ntpd when: ansible_os_family in ['RedHat', 'Suse'] - name: setup ntp daemon block: - name: install and enable timesyncd command: timedatectl set-ntp on when: ntp_daemon_type == "timesyncd" notify: - disable ntpd - disable chronyd - name: disable time sync using timesyncd if we are not using it command: timedatectl set-ntp no when: ntp_daemon_type != "timesyncd" - name: setup ntpd when: ntp_daemon_type == "ntpd" block: - name: install ntp package: name: ntp state: present register: result until: result is succeeded - name: enable and start ntp service: name: "{{ ntp_service_name }}" enabled: yes state: started notify: - disable chronyd - disable timesyncd - name: setup chronyd when: ntp_daemon_type == "chronyd" block: - name: install chrony package: name: chrony state: present register: result until: result is succeeded - name: enable and start chronyd service: name: chronyd enabled: yes state: started notify: - disable chronyd - disable timesyncd