--- - name: Set ntp service and chrony daemon name for Debian family ansible.builtin.set_fact: chrony_daemon_name: chrony ntp_service_name: ntp when: ansible_facts['os_family'] == 'Debian' - name: Set ntp service and chrony daemon name for RedHat and Suse family ansible.builtin.set_fact: chrony_daemon_name: chronyd ntp_service_name: ntpd when: ansible_facts['os_family'] in ['RedHat', 'Suse'] # Installation of NTP daemons needs to be a separate task since installations # can't happen on Atomic - name: Install the ntp daemon when: not is_atomic | bool block: - name: Install ntpd ansible.builtin.package: name: ntp state: present register: result until: result is succeeded when: ntp_daemon_type == "ntpd" - name: Install chrony ansible.builtin.package: name: chrony state: present register: result until: result is succeeded when: ntp_daemon_type == "chronyd" - name: Enable the ntp daemon and disable the rest block: - name: Enable timesyncing on timesyncd ansible.builtin.command: timedatectl set-ntp on notify: - Disable ntpd - Disable chronyd changed_when: false when: ntp_daemon_type == "timesyncd" - name: Disable time sync using timesyncd if we are not using it ansible.builtin.command: timedatectl set-ntp no changed_when: false when: ntp_daemon_type != "timesyncd" - name: Enable ntpd ansible.builtin.service: name: "{{ ntp_service_name }}" enabled: true state: started notify: - Disable chronyd - Disable timesyncd when: ntp_daemon_type == "ntpd" - name: Enable chronyd ansible.builtin.service: name: "{{ chrony_daemon_name }}" enabled: true state: started notify: - Disable ntpd - Disable timesyncd when: ntp_daemon_type == "chronyd"