-
  name: "Block to Allow Loading of Variables without running task"
  when: run_tasks
  block:
    -
      name: "Including OS-specific variables."
      ansible.builtin.include_vars: "{{ ansible_os_family }}.yml"
    
    -
      name: "Setting the ntp_driftfile variable."
      ansible.builtin.set_fact:
        ntp_driftfile: "{{ __ntp_driftfile }}"
      when: ntp_driftfile is not defined
    
    -
      name: "Setting the ntp_package variable."
      ansible.builtin.set_fact:
        ntp_package: "{{ __ntp_package }}"
      when: ntp_package is not defined
    
    -
      name: "Setting the ntp_config_file variable."
      ansible.builtin.set_fact:
        ntp_config_file: "{{ __ntp_config_file }}"
      when: ntp_config_file is not defined
    
    -
      name: "Setting the ntp_daemon variable."
      ansible.builtin.set_fact:
        ntp_daemon: "{{ __ntp_daemon }}"
      when: ntp_daemon is not defined
    
    -
      name: "Ensuring NTP package is installed."
      ansible.builtin.package:
        name: "{{ ntp_package }}"
        state: present
    
    -
      name: "Ensuring tzdata package is installed (Linux)."
      ansible.builtin.package:
        name: "{{ ntp_tzdata_package }}"
        state: present
      when: ansible_system == "Linux"
    
    -
      name: "Setting timezone."
      community.general.timezone:
        name: "{{ ntp_timezone }}"
      notify: restart cron
    
    -
      name: "Populating service facts."
      ansible.builtin.service_facts:
    
    -
      name: "Disabling systemd-timesyncd if it's running but ntp is enabled."
      ansible.builtin.service:
        name: systemd-timesyncd.service
        enabled: false
        state: stopped
      when:
        - ntp_enabled | bool
        - ansible_facts.services["systemd-timesyncd"] is defined
    
    -
      name: "Ensuring NTP is running and enabled as configured."
      ansible.builtin.service:
        name: "{{ ntp_daemon }}"
        state: started
        enabled: true
      when: ntp_enabled | bool
    
    -
      name: "Ensuring NTP is stopped and disabled as configured."
      ansible.builtin.service:
        name: "{{ ntp_daemon }}"
        state: stopped
        enabled: false
      when: not (ntp_enabled | bool)
    
    -
      name: "Generating ntp configuration file."
      ansible.builtin.template:
        src: "{{ ntp_config_file | basename }}.j2"
        dest: "{{ ntp_config_file }}"
        mode: "0644"
      notify: restart ntp
      when: ntp_manage_config | bool
